![](https://pdfstore-manualsonline.prod.a.ki/pdfasset/3/8d/38d56254-54fe-46e3-85ae-d3f5260e1091/38d56254-54fe-46e3-85ae-d3f5260e1091-bg8c.png)
FX Series Programmable Controlers Applied Instructions 5
5-14
Nested FOR-NEXT loops:
FOR-NEXT instructions can be nested for 5 levels. This means that 5 FOR-NEXT loops can be
sequentiall
pro
rammed within each other.
In the example a 3 level nest has been pro
rammed. As each new FOR-NEXT nest level is
encountered the number of times that loop is repeated is increased b
the multiplication of all
of the surroundin
/previous loops.
For example, loop C operates 4 times. But within
this loop there is a nested loop, B. For ever
completed c
cle of loop C, loop B will be
completel
executed, i.e. it will loop D0Z times.
This a
ain applies between loops B and A.
The total number of times that loop A will operate
for ONE scan of the pro
ram will equal;
1) The number of loop A operations multiplied b
2) The number of loop B operations multiplied b
3) The number of loop C operations
If values were associated to loops A, B and C, e.
.
7, 6 and 4 respectivel
, the followin
number of
operations would take place in ONE pro
ram
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 pro
rammin
feature, causin
the
ump to P22 allows the ‘selection’ of
which loop will be processed and when, i.e. if X10 was switched ON, loop A would no lon
er
operate.