GLBasic User Manual

Main sections

FOR

FOR counter# = start# TO end# |STEP steps#|
...
NEXT



The FOR statement defines a section of code to be looped over as long as a counter is within the range of start# to end#.
On initial execution the value of counter# is set to start#. At the end of every pass of the loop, counter# will be increased (or decreased) by the value in steps#. If steps# is not defined, steps# defaults to +1. The code will loop until counter# is not in the range of [start#; end#] anymore.
A BREAK statement will immediately abort the loop and continue running the code immediately after the 'NEXT 'statement.
A CONTINUE statement placed somewhere in the loop will cause the program to behave like it had just read the 'NEXT' statement.

Sample:
 
FOR i=0 TO 10 STEP 2
PRINT i, 100, 32*i
NEXT

SHOWSCREEN
MOUSEWAIT


Output :
0
2
4
6
8
10

See also...