step -1

BlitzMax Forums/BlitzMax Beginners Area/step -1

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Keep in mind that "Step -1" is not subtraction. It ADDS -1 to the loop variable.

There is no number -1 for a byte, so -1 is replaced by the equivalent 255. The original example becomes
Local t:Byte
For t=10 to 0 Step 255     ' used to be -1
Next
and the loop is never entered.

You can also get bizarre results with ordinary integers by using an inappropriate step size.
Local n:Int

For n = 1 To 2000000000 Step 600000000
    Print n
Next
Here the problem is that we step past the final value while wrapping around to negative numbers. The loop doesn't terminate until we land on a suitably large positive number.