31.6.4.2 Explanation of FOR and NEXT Instructions

FOR and NEXT instructions repeat the logic between FOR and NEXT the number of times specified in S1. After the processing between the FOR and NEXT instructions has been executed the number of times specified in S1, the rung that follows the NEXT instruction will run without any conditions. When S1 is 0 or less, the logic between FOR and NEXT will not execute and the program will jump to the rung that follows the NEXT instruction.

Always use FOR and NEXT instructions as a pair. These instructions always run.

Program Example

FOR/NEXT

Other instructions cannot coexist on the same rung as FOR and NEXT instructions. You can use a JMP instruction to specify conditions for executing FOR and NEXT instructions. The following program example of FOR and NEXT instructions shows how you can use a condition to run FOR and NEXT instructions.

When the variable of the normally open instruction turns ON FOR and NEXT will not execute, and the program will jump to "LABEL-001". When the variable is OFF, the FOR and NEXT instructions execute. The value (N) of the FOR instruction's operand S1 indicates the number of times that the rungs between the FOR and NEXT instructions will be repeated. When S1 = 10, the FOR loop is repeated 10 times. After exiting the FOR loop, processing continues with instructions that follow the NEXT instruction.