Rockwell Automation 57C610 Enhanced Basic Language, AutoMax User Manual
Page 54

6Ć14
where:
variable = simple numeric variable known as the loop index.
expression_1 = initial value of the index; can be any
numeric expression.
expression_2 = terminating condition; can be any
numeric expression.
expression_3 = incremental value of the index; the STEP size
is optional. If specified, it can be positive or
negative; if not specified, the default is +1.
Expression_3 can be any numeric expression.
The NEXT statement has the following format:
NEXT variable
where:
variable = same variable named in the corresponding FOR
statement
The FOR and NEXT statements must be used together. You cannot
use one without the other. If you do, the program cannot be
compiled. The FOR statement defines the beginning of the loop; the
NEXT statement defines the end. Place the statements you want
repeated between the FOR and NEXT statements. You are actually
building a counter in your program to determine the number of
times the loop is to execute when you use FOR and NEXT.
Here is a simple FORĆNEXT statement example:
20 FOR M% = 30 TO 90 STEP 3
30...
40...
50 NEXT M%
M% is given the initial value of 30, and BASIC tests to determine if
M% is less than or equal to the terminating value of 90. The loop is
executed because M% is less than 90. When the NEXT statement is
encountered, the value of M% is incremented by 3. BASIC goes
back to line 20 and tests again to see if M% is greater than 90. When
BASIC reaches the NEXT statement and M% has a value of 87,
BASIC adds 3 to M% and tests the result against the terminating
value. The result, 90, is not greater than the terminating value of 90,
so BASIC executes the loop again. When BASIC reaches the NEXT
statement again, it adds 3 to M%, producing 93. Because this is
greater than the terminating value, BASIC terminates the loop by
transferring control to the next sequential statement after the NEXT
statement.
The following program will print the numbers 1 through 11 as shown
below the program listing:
10 FOR I% = 1 TO 10
20 PRINT I%
30 NEXT I%
40 PRINT I%
50 END
1
2
3