Home
Free Midlets
Help

FOR / TO / STEP / NEXT

Syntax: FOR var%=n1 TO n2 [STEP n3] … NEXT var

var, n1, n2 and n3 must all be integer.

Example 1

FOR I%=1 TO 10: PRINT I%:NEXT I%

Example 2

 
10 FOR X=1 TO 10
20 PRINT X
30 NEXT X

The above example counts from 1 through to 10 in steps of 1. If you don't want to count in steps other than 1 then you must specify it using "STEP n". For example, to count down from 99 through to 11 in steps of –11 you should enter:-

10 FOR X=99 TO 11 STEP -11
20 PRINT X
30 NEXT X

It is also possible to nest FOR NEXT loops within another FOR NEXT LOOP.

10 FOR X=1 TO 10
20 PRINT X
30 FOR Y=1 TO 10
40 PRINT Y
50 NEXT Y
60 NEXT X