79
4
4 Instructions 4.2.4 Loop
NEXT: End of a loop
◆
Overview
The NEXT instruction identies the end position of a loop.
NEXT
End of a loop Applicable model:
H3U
An independent instruction without operands
16-bit instruction
(1 step)
NEXT:
Continuous
execution
◆
Function
The NEXT instruction identies the end position of a loop area. After a For/Next loop indicated by the FOR
instruction is repeated N times, the PLC proceeds to subsequent execution.
The For/Next loop can be nested for six levels starting from the outermost level. The PLC executes parsing
at the six levels in sequence. When the number of repeats for a loop is great, the PLC scan duration
increases, which may result in an error when the watchdog timer times out. To avoid this error, insert the
WDT instruction between the FOR and NEXT instructions.
• An error occurs in the following conditions:
The NEXT instruction precedes the FOR instruction.
• The FOR instruction exists without the NEXT instruction.
• In FEND, the END instruction is followed by the NEXT instruction.
• The FOR and NEXT instructions are not equal in quantity.
Example 1:
ĂĂ
Loop 3
ǒFOR K2Ǔ
ǒNEXTǓ
ǒFOR K4Ǔ
ǒFOR K3Ǔ
ǒNEXTǓ
Loop 2
Loop 1
ǒNEXTǓ
ǒENDǓ
After loop 1 is executed twice, it will be
executed in the program following the NEXT
instruction. Loop 2 is executed three times
each time loop 1 is executed, and loop 3 is
executed four times each time loop 2 is
executed. Therefore, loop 3 is executed 24
times (= 2 x 3 x 4) in total, and loop 2 is
executed six times (= 2 x 3) in total.