FOR .. NEXT Verbs
Syntax
FOR numname=numA TO numB {STEP numC}
…
NEXT numname
Description
For BBj specific information, see the FOR
.. NEXT Verbs - BBj.
The FOR/NEXT verb loop is a looping construction that operates according
to the following sequence:
-
numname is set to numA.
-
numB, and, optionally, numC, are evaluated. (If numC is not given, its value defaults to 1. It cannot be zero.)
-
The results are saved.
-
The FOR loop information is preserved on a FOR/GOSUB stack used later by a NEXT statement. Execution continues with the statement that follows.
-
If the STEP value is positive and numname is greater than the TO value, or if the STEP value is negative and numname is less than the TO value, the FOR entry on the FOR/GOSUB stack is discarded and execution continues with the statement following the NEXT. Otherwise, execution continues with the statement following the corresponding FOR.
If the top entry on the FOR/GOSUB stack is not a FOR statement entry,
or if the numname does not match,
PRO/5 issues an error.
A FOR .. NEXT loop always executes at least once because the termination
check is performed at the NEXT statement. PRO/5 also supports the looping
constructs REPEAT .. UNTIL
and WHILE .. WEND.
FOR .. NEXT loops may be nested until the application runs out of memory
or simple numeric variables. FOR or NEXT cannot be used in console mode.
Examples
Example 1
The following prints the N value 100 times.
1000 FOR N=1 TO 100
1010 PRINT N
1020 NEXT N
Example 2
The following prints the N value 50 times.
1000 FOR N=1 TO 100 STEP 2; PRINT N; NEXT N