1. FOR-NEXT Loop Instruction

1. FOR-NEXT Loop Instruction

1.1. Instruction Description

When the input terminal is turned on, execute this command. Each FOR instruction must be paired with a NEXT instruction, and all instruction segments between FOR and NEXT instructions will be executed repeatedly (CNT) times. The instruction must specify the number of iterations CNT value. The NEXT instruction marks the end of the FOR loop.

CNT values can be modified during the execution of the FOR/NEXT loop. When the loop is allowed again, the number of loops is executed according to the new CNT value. When allowed next time, the FOR/NEXT instruction resets itself.

When the input terminal is enabled as' disconnected ', the program will skip all instruction segments between FOR and NEXT and directly execute the instructions after the NEXT instruction.

Note: The maximum number of nested layers for the FOR -- NEXT loop is 8

1.2. The valid operands of the instruction

Input/Output Data Type operand Description
N 16 bit integer D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) tags

1.3. Example

command table:

NETWORK 000

LDP X000

FOR K10 // For loop 10 times

NETWORK 001

LD X001

INC D0 D0 // Add 1 D0 per cycle

NETWORK 002

NEXT

FOR11

图1 FOR11

FOR12

图2 FOR12