Skip to main content

Loop Begin (FOR)

Instruction Parameters

Supported PLC Series

XPnA/1RXPnBXPnEXPnFCP3A/B/P/U
CP4A~D/U
CPnECPnFBPPLC-S

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.

Examples