Mitsubishi Electronics FX2C Home Theater Server User Manual


 
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
y
pro
g
rammed within each other.
In the example a 3 level nest has been pro
g
rammed. As each new FOR-NEXT nest level is
encountered the number of times that loop is repeated is increased b
y
the multiplication of all
of the surroundin
g
/previous loops.
For example, loop C operates 4 times. But within
this loop there is a nested loop, B. For ever
y
completed c
y
cle of loop C, loop B will be
completel
y
executed, i.e. it will loop D0Z times.
This a
g
ain applies between loops B and A.
The total number of times that loop A will operate
for ONE scan of the pro
g
ram will equal;
1) The number of loop A operations multiplied b
y
2) The number of loop B operations multiplied b
y
3) The number of loop C operations
If values were associated to loops A, B and C, e.
g
.
7, 6 and 4 respectivel
y
, the followin
g
number of
operations would take place in ONE pro
g
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
g
rammin
g
feature, causin
g
the
j
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
g
er
operate.