Repeat loop with negative step caught me offguard
Agent420
Posts: 439
I was coding a simple repeat loop in Spin last night that used a negative step, and couldn't figure out why it wasn't working - it would execute the first value and then quit...
My Basic and C coding habits caused me to insert the 'step -1' value without thought.· Turns out Spin is smart enough to know when the loop is going backwards and automatically defaults to a step of -1, so I was counteracting it's behavior [noparse]:)[/noparse]
I guess that implementation makes sense, but it's·another one of those Spin things that caught me off guard.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
repeat x from 7 to 0 step -1 blah blah blah
My Basic and C coding habits caused me to insert the 'step -1' value without thought.· Turns out Spin is smart enough to know when the loop is going backwards and automatically defaults to a step of -1, so I was counteracting it's behavior [noparse]:)[/noparse]
I guess that implementation makes sense, but it's·another one of those Spin things that caught me off guard.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Comments
So in your case without the negative step -1 statment the variable x will be left at -1.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
I always like to setup the counter and loop increment myself. I hate trying to remember the details of the short-hand notations so I like to be able to specify the exact termination condition and exactly when the count is incremented.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
but the bug of it is that if you do put the "step -1" in it should work [noparse];)[/noparse]
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propeller Tools
The law of the land is the law. Or in this case the law of the language. Doing it this way seems logical enough to me. Still, it would be nice if this kind of thing was the same across all languages.