# FOR

Compatible with:
DOS Maximite CMM MM150 MM170 MM+ MMX Picromite ArmiteL4 Armite F4 ArmiteH7 Picomite CMM2

Syntax:
FOR counter = start TO finish [STEP increment]
NEXT [counter-variable] [, counter-variable], etc
CONTINUE FOR
EXIT FOR

Description:

FOR counter = start TO finish [STEP increment]
Initiates a FOR-NEXT loop with the 'counter' initially set to 'start' and incrementing in 'increment' steps (default is 1) until 'counter' is greater than 'finish'.
The ‘increment’ can be an integer or floating point number.
Note that using a floating point fractional number for 'increment' can accumulate rounding errors in 'counter' which could cause the loop to terminate early or late.
'increment' can be negative in which case 'finish' should be less than 'start' and the loop will count downwards.

NEXT [counter-variable] [, counter-variable], etc
NEXT comes at the end of a FOR-NEXT loop; see FOR.
The ‘counter-variable’ specifies exactly which loop is being operated on.
If no ‘counter-variable’ is specified the NEXT will default to the innermost loop. It is also possible to specify multiple variables as in: NEXT x, y, z

CONTINUE FOR
Skip to the end of a FOR/NEXT loop. The loop condition will then be tested and if still valid the loop will continue with the next iteration.

EXIT FOR
EXIT FOR provides an early exit from a FOR...NEXT loop.

FOR n = 1 TO 5
PRINT n
NEXT n
PRINT n
PRINT
FOR n = 1 TO 10
IF n < 3 THEN CONTINUE FOR ' skip the remainder of the loop if N < 3
PRINT n
IF n >= 5 THEN EXIT FOR
NEXT n
PRINT n
Output:
1
2
3
4
5
6
3
4
5
5
' Example of using a float and fractional step
' note that the loop finishes before the last value due to floating point numbers.
DIM FLOAT Vin
FOR Vin = 0 TO 3.3 STEP 0.1
PRINT Vin
NEXT Vin
' to complete the loops, add a small value to the end point, smaller than the step.
FOR Vin = 0 TO 3.31 STEP 0.1
PRINT Vin
NEXT Vin

Last edited: 29 September, 2022