FX Series Programmable Controlers Applied Instructions 5
5-15
Nested FOR-NEXT loops:
FOR-NEXT instructions can be nested for 5 levels. This means that 5 FOR-NEXT loops can be
sequentially programmed within each other.
In the example a 3 level nest has been programmed. As each new FOR-NEXT nest level is
encountered the number of times that loop is repeated is increased by the multiplication of all
of the surrounding/previous loops.
For example, loop C operates 4 times. But within
this loop there is a nested loop, B. For every
completed cycle of loop C, loop B will be
completely executed, i.e. it will loop D0Z times.
This again applies between loops B and A.
The total number of times that loop A will operate
for ONE scan of the program will equal;
1) The number of loop A operations multiplied by
2) The number of loop B operations multiplied by
3) The number of loop C operations
If values were associated to loops A, B and C, e.g.
7, 6 and 4 respectively, the following number of
operations would take place in ONE program
scan:
Number of loop C operations = 4 times
Number of loop B operations = 24 times (C × B, 4 × 6)
Number of loop A operations = 168 times (C × B × A, 4 × 6 × 7)
FOR K 4
FOR D 0Z
X10
CJ P 22
FOR K1X0
NEXT
NEXT
NEXT
P22
AB C
Note:
The use of the CJ programming feature, causing the jump to P22 allows the ‘selection’ of
which loop will be processed and when, i.e. if X10 was switched ON, loop A would no longer
operate.