intel MCS BASIC-52 — Intel MCS BASIC-52 Versions 1 & 1.1 Operating and Reference Manual PDF (EN)

int e l 4.11 DESCRIPTION OF STATEMENTS STATEMENTS: FOR -- TO -- {STEP} -- NEXT MODE: RUN VERSION 1.0 (COMMAND AND/OR RUN in Version 1.1) TYPE: CONTROL The FOR -- TO -- {STEP}—NEXT STATEMENTS are used to set up and control loops. EXAMPLE: 10 FOR A=3 TO C STEP D 20 PRINT A 30 NEXT A If B = 0, C = 10, and D = 2, the PRINT STATEMENT at line 20 will be executed 6 times. The values of "A" that will be printed are 0, 2, 4, 6, 8, 10. "A" represents the name of the index or loop counter. The value of "B" is the starting value of the index, the value of "C" is the limit value of the index, and the value of "D" is the increment to the index.

If the STEP STATEMENT and the value "D" are omitted, the increment value defaults to 1, therefore, STEP is an optional statement. The NEXT STATEMENT causes the value of "D" to be added to the index. The index is then compared to the value of "C," the limit. If the index is less than or equal to the limit, control will be transferred back to the statement after the FOR STATEMENT. Stepping "backwards" (i.e. FOR I = 100 TO 1 STEP-1) is permitted in MCS BASIC-52. Unlike some BASICS, the index MAY NOT be omitted from the NEXT STATEMENT in MCS BASIC-52 (i.e. the NEXT statement MUST always be followed by the appropriate variable). EXAMPLES:

>10 FOR I=1 TO 4 >10 FOR I=0 TO 8 STEP 2 >20 PRINT I >20 PRINT I >30 NEXT I >30 NEXT I >RUN >RUN 1 0 2 2 3 4 4 6 8 READY > READY > - 39 -