Blitz3D+ Command Reference

To limit

Parameters

limit - the value the loop counter runs up (or down) to; any numeric expression

Description

Separates the start and end values of a For loop.

To only appears inside a For line: For frame = 1 To 30. The limit is inclusive, so that loop runs thirty times and the last pass has frame equal to 30. Counting an array is the usual case - For i = 0 To 9 covers every slot of a ten element array.

The limit does not have to be a plain number. Any expression works, including a variable or a function call, and it can be a float when the counter is a float. What it must not be is expensive, because it is re-evaluated on every single pass of the loop. Store the result in a variable before the loop if it costs anything to work out.

To count downwards the limit goes below the start and the loop needs a negative Step: For i = 10 To 1 Step -1. Without the negative step the loop simply never runs, because the counter starts past the limit and the test happens before the first pass.

See also: For, Step, Next, Each, Exit.

Example

; To Example
; ----------

; To sets the range the counter runs through - here 1 up to 5
Print "Launch checklist:"
For stage=1 To 5
    Print "    Stage "+stage+" ... check!"
Next

Print ""

; When the first value is higher than the second, use a negative Step
Print "Countdown:"
For count=5 To 1 Step -1
    Print "    "+count+" ..."
Next
Print "    Lift off!"

Print ""
Print "Press any key to close the example"
WaitKey

End

Index