137
FNC
08
FNC
09
N E X T
1
1
2
2
M
M
3
3
○
○
○
○
○
○
○
○
X
S
Y M S
D.b R.b
KnX KnY
KnM KnS
T C
D,R
V,Z
UnG
K,H
E
" $"
S =1~32,767 (beyond the range, the set value S is regarded as 1)
NEXT
NEXT
NEXT
NEXT
〜〜〜〜〜
FOR K3
FOR D0
FOR K1X20
M9000
M9000
Z0
RST
D10
RST
FOR K10
NEXT
ADD D10 D0Z0 D10
INC Z0
1
2
3
F O R
S
FOR K5
S
S
Start of a FOR-NEXT Loop
End of a FOR-NEXT Loop
Operand
Devices
The LOOPING segment
in program
S : the number of times to be repeated in the FOR-NEXT loop.
The program segment in the FOR-NEXT loop will be executed
times.
As in the left diagram, the LOOPING segment in program is
executed 5 times sequentially.
In a FOR-NEXT loop, the CJ instruction can be used to jump out of the loop.
At most 5 levels can be used for a nest FOR~NEXT loop. Be sure to note that the loops will cause the currently
Scan Time extended. The Scan Time should be taken not to exceed WDT’s default value, otherwise an error will
occur.
Errors will occur under the following circumstances:
The NEXT instruction is placed in front of the FOR instruction.
The NEXT instruction is placed behind the FEND or END instruction.
The FOR instruction and the NEXT instruction are not programmed as a pair.
Multiple-level Loop Program
3-Level Loop
Use the FOR-NEXT Loop instructions to combine with the Pointer Register V, Z that will make the program more
exible. The program below will add up the content value of D0~D9 and store the result in D10.