FOR/NEXT
Loop Controlled by Counter
This directive provides the ability to repeat a segment of program a specified number of times.
Syntax
Section titled “Syntax”FOR numeric-variable = numeric-value1 TO numeric-value2{STEP numeric-value3]NEXT numeric-variablenumeric-variable- is any valid numeric variable name.
numeric-value1,2,3- is any number.
Remarks
Section titled “Remarks”This directive starts numeric-variables at numeric-value1 and increment numeric-variable by numeric-value3 (or 1 if not specified) each time the NEXT is executed until numeric-value2 is equalled or exceeded.
This directive places a return address pointer on the stack of scheduled places to go in order to show the NEXT portion where to return. This pointer is removed when the loop is terminated normally by NEXT (numeric-variable reaches or exceeds value2) or an EXITTO directive abnormally terminates the loop.
The NEXT that is paired with this FOR directive must have the same numeric-variable name.
There may exist more than one NEXT for the same FOR/NEXT loop.
Examples
Section titled “Examples”01000 FOR NUM_VAL = 10 TO 500001010 FOR BACK_LOOP = NUM_VAL TO 2 STEP -101020 IF FPT(NUM_VAL/BACK_LOOP)=0 AND NUM_VAL<>BACK_LOOP THEN EXITTO 0105001030 NEXT BACK_LOOP01040 PRINT NUM_VAL01050 NEXT NUM_VALprints all prime numbers from 10 to 5000.
See also
Section titled “See also”WHILE/WEND directive
From the Thoroughbred Basic Language Reference, Volume II: F–Q, version 8.9.1. Open this page in the PDF