The leader in industrial automation and control solutions

Instruction Parameters

Supported PLC Series

PLC-AESPLC-FBPLC-ES

Supported Data Registers

MXYKLFTCSZRQD@DConstant
n

Supported Flags

FlagBitSupport
ErrorF11.0
ZeroF11.1
CarryF11.2

Number of Steps

Steps
1

Operands

OperandDescription
nThe only operand.
Entries are WORD data registers or constants.
This is the number of times to repeat the instructions inside the loop statement.

The value range is 1 ~ 32,767 (215-1).

Notice

Error Flag (F11.0) Notice

The error flag, F11.0, will be ON for one scan when the address of the data register assigned by @D exceeds the range of the data register, D. The range of the data register, D, is dependent on the CPU type.

  • Compile errors occur under the following conditions:
    • When the value of n exceeds the range 1 ~ 32,767 (215-1).
    • When the FOR ~ NEXT instructions are not used as a pair.
    • When the FOR ~ NEXT instructions exceed 16 levels.

Instruction Behavior

The FOR instruction behaves as follows:

  • Instructions within the bounds of the FOR ~ NEXT instruction are executed n times.
    • When the loop ends, the instruction after the NEXT instruction is executed.
  • Nesting FOR ~ NEXT instructions is possible up to 16 nests.
  • The FOR ~ NEXT instructions must be used in pairs.

Excessive Use

If the FOR ~ NEXT instructions are used excessively, the scan time increases. The system might be overloaded causing the CPU to shut down or initialize.

Ladder Diagram Examples

FOR

The FOR instruction defines the beginning of n loops.

The FOR instruction defines the beginning of n loops.

- The order of execution is as follows:
  • The order of execution is as follows:
    1. The INCP D100 instruction will increase the data register, D100, by 1 every second.
    2. The INCP D0 instruction will increase the data register, D0, by 1 every second.
    3. Step 1 and step 2 will repeat 500 times.
      • After 500 times in the loop, 1 scan is finished.
    4. After 500 times in the loop, the DECP D200 instruction will resume execution.