Rockwell Automation 57C610 Enhanced Basic Language, AutoMax User Manual

Page 56

Advertising
background image

6Ć16

A loop can contain one or more loops provided that each inner loop

is completely contained within the outer loop. Using one loop within

another is called nesting. Each loop within a nest must contain its

own FOR and NEXT statements. The inner loop, the one that starts

first, must terminate before the outer loop, which must be completed

last. Loops cannot overlap.
The following are two legal nested loops:

10 FOR A%=1% TO 10%

10 FOR A%=1 TO 10

20 FOR B=2 TO 20

20 FOR B=2 TO 20

30 NEXT B

30 NEXT B

40 NEXT A%

40 FOR C%=3 TO 30
50 FOR D=4 TO 40
60 FOR E=5 TO 50
70 NEXT E
80 NEXT D
90 NEXT C%
100 NEXT A%

The following is a program with a legal nested loop:

10 PRINT I", J"
15 PRINT
20 FOR I%=1 TO 2
30 FOR J%=1 TO 3
35 !
40 PRINT I%,J%
45 !
50 NEXT J%
60 NEXT I%
70 END

Inside

Loop

Outside

Loop

Running the above program would display:
ăăĂĂĂĂI J

1 1
1 2
1 3
2 1
2 2
2 3

Inside

Loop

The following is an illegal nested loop because the inner loop does

not terminate first:

10 FOR M=1 TO 10
20 FOR N=2 TO 20
30 NEXT M
40 NEXT N

FOR and NEXT statements are commonly used to initialize arrays.

As illustrated in this example, line 5 defines a local array with 6 rows

and 11 columns. For more information, see section 6.1.1.

ă5 LOCAL X%(5,10)
10 FOR A%=1 TO 5

Advertising
This manual is related to the following products: