`prev Menu next`

FOR ～ NEXT (FOR-block) ☆☆☆
A FOR～NEXT block is written as the form
`FOR Control_Var = Initial_Value TO Limit STEP Increment
………
NEXT Control_Var
`
Control_Var is a numeric simple variable (any indexed variable not allowed).
Initial_Value, Limit, and Increment are numeric expressions.
NEXT statement must have the same variable written in the FOR statement.
Limit and Increment are computed only when the FOR statement is executed, those values remain unchanged while the repetition progresses.
If the increment is positive, the repetition acts as follows.
(1) Initial_Value is assigned to Control_Var.
(2) If Control_Var is greater than the limit, the control branches to the next line of the NEXT line.
(3) When the NEXT line is executed, Control_var is added the increment, and the control goes back to (2).
If the increment is negative, the comparison in (2) is inverted.
Example

    10 FOR N=10 TO 1 STEP -1
    20    PRINT N
    30 NEXT N
    40 END

"STEP Increment" can be omitted. On that case, the increment is assumed to be 1.
EXIT FOR
Use EXIT FOR to escape from a FOR ～ NEXT repetition.
Example.

    10 INPUT n
    20 FOR f=2 TO n-1
    30    IF MOD(n,f)=0 THEN
    40       PRINT f
    50       EXIT FOR
    60    END IF
    70 NEXT f
    80 END

If a EXIT FOR has nested FOR～NEXT blocks that include it, the execution of it means the escape from the most inner FOR block.