For-to-(step)-next, For-to-(step)-next -6, Purpose – Rockwell Automation 1746-BAS BASIC LANGUAGE User Manual
Page 90: Syntax, Examples
Publication 1746-RM001A-US-P
7-6 Control Functions
FOR-TO-(STEP)-NEXT
Purpose
Use the FOR- TO-(STEP)-NEXT statement to set up and control program loops.
The control stack (C-stack) stores all information associated with loop control
(example: DO-WHILE, DO-UNTIL, FOR-NEXT and BASIC subroutines). The
control stack is 157 bytes long. DO-WHILE and DO-UNTIL loops and GOSUB
commands use 3 bytes of the control stack. FOR-NEXT loops use 17 bytes.
Syntax
FOR [expr] TO [expr] STEP [expr]
.
.
.
NEXT [expr]
Examples
>1
REM EXAMPLE PROGRAM
>5
E=0 : C=10 : D=2
>10 FOR A=E TO C STEP D
>20 PRINT A
>30 NEXT A
>40 END
>RUN
0
2
4
6
8
10
READY
>1
REM EXAMPLE PROGRAM
>10 FOR I = 1 TO 4
>20 PRINT I,
>30 NEXT I
>40 END
READY
>RUN
1
2
3
4
IMPORTANT
Excessive nesting exceeds the limits of the control stack,
generating an error, and causing the module to enter Command
mode.