Rockwell Automation 57C610 Enhanced Basic Language, AutoMax User Manual
Page 55
6Ć15
4
5
6
7
8
9
10
11
In the above program, the initial value of the index variable is 1. The
terminating value is 10, and the STEP size is + 1(the default). Every
time BASIC goes to line 30, it increments the loop index by 1 (the
STEP size) until the terminating condition is satisfied. The
terminating condition is satisfied when the control variable is greater
than 10. Therefore, this program prints the values of I% ten times.
When the loop is completed, execution proceeds to line 40 and
prints I% again which has been incremented already to 11. When
control passes from the loop, the last value of the loop variable is
retained. Therefore, I% equals 11 on line 40.
You can modify the index variable within the loop. The loop in the
program below only executes once because at line 20 the value of
1% is changed to 44 and the terminating condition is reached.
10 FOR I% = 2 TO 44 STEP 2
20 LET I% = 44
30 NEXT I%
40 END
If the initial value of the index variable is greater than the terminal
value, the loop is never executed. The loop below on the left cannot
execute because you cannot decrease 20 to 2 with increments of
+2. You can, however, accomplish this with increments of -2 as
shown in the right loop.
10 FOR 1 = 20 TO 2 STEP 2
10 FOR 1 = 20 TO 2
ąąąąąąąąąąąąąąSTEP -2
It is possible to jump out of a FOR loop that has been started or
executed at least once, but you should not transfer control into a
FOR loop that has not been initialized by executing the FOR
statement. It will result in a fatal error during run time and the task
will be stopped. The following is illegal in a BASIC task because line
20 shifts control to line 40, bypassing line 30:
10 ! THIS IS ILLEGAL
20 GO TO 40
30 FOR I=1 TO 20
40 PRINT I
50 NEXT I
60 END
FOR and NEXT statements can be placed anywhere in a
multiĆstatement line:
10 FOR I%=1 TO 10 STEP 5\ PRINT I%\ NEXT I%
20 END