M800V/M80V Series PLC Programming Manual (1/2)
8 Function Instructions
8.5 Program Branch Instructions
Operation errors
In the following cases, an arithmetic error occurs, the error flag (SM0) turns ON, and an error code is stored at SD0.
- An END (FEND) instruction is executed after the execution of a FOR instruction, but before the execution of a NEXT
instruction. (Error code: 31)
- A NEXT instruction is executed prior to the execution of a FOR instruction. (Error code: 31)
- The 17th FOR instruction is encountered when FOR instructions have been nested. (Error code: 30)
Program example
The following program executes the FOR to NEXT loop when X8 is OFF, and does not execute it when X8 is ON.
0
3
6
8
16
P8
17
20
[Remark]
Use an EGP/ EGF instruction to change an index of contacts between FOR and NEXT.
IB-1501667-B
[Ladder mode]
X8
CJ P8
M0
MOV K0 D100
FOR K4
M0
MOV D100 Z0
MOV D100 D0Z0
INC D100
NEXT
XA
Steps
0
1
3
4
6
8
9
12
15
16
17
18
Y33
19
20
END
260
[List mode]
Inst.
Device
LD
X8
CJ
P8
LDI
M0
MOV
K0
D100
FOR
K4
LDI
M0
MOV
D100
Z0
MOV
D100
D0Z0
INC
D100
NEXT
P8
LD
XA
OUT
Y33
END