FOR VAR = EXP1 TO EXP2 {STEP EXP3}

The FOR.. TO statement is partner to the NEXT statement. If you have a FOR statement, you must have a matching NEXT statement. The default increment for the FOR..NEXT loop is one. If you wish to change this, you can use the STEP EXP3 part of the statement. Every time a NEXT is executed, the variable VAR will be incremented (or decremented - depending upon whether EXP3 is negative or positive) by EXP3. If the loop is to be exited early, you should make use of the NEXT * construct or a STACK OVERFLOW error will occur.

Program Examples (A simple FOR..NEXT loop).

00100 FOR I = 1 TO 100
00110 PRINT I
00120 NEXT I
00130 END 

A FOR..NEXT loop utilising variables as the upper and lower bounds.

Try it

00100 Z = 1000
00110 B = 1050
00120 FOR I = Z TO B
00130 PRINT I
00140 NEXT I
00150 END  

Try it

A FOR..NEXT loop utilising the STEP option.

00100 FOR I = 1 TO 100 STEP 10
00110 PRINT I
00120 NEXT I
00130 END 

Try it

For information on the NEXT * option etc., see the listing under NEXT in this summary.

See also NEXT, NEXT*.