205
3. Instructions
CS/CJ/NSJ Series Instructions Reference Manual (W474)
Sequence Control Instructions
3
FOR/NEXT
FOR/NEXT
Applicable Program Areas
Operands
N: Number of loops
The number of loops must be 0000 to FFFF (0 to 65,535 decimal).
z Operand Specifications
Flags
Function
Note If a loop repeats in one cycle and a differentiated bit is used in the FOR-NEXT loop, that bit will be always ON or always
OFF within that loop.
Instruction Mnemonic Variations
Function
code
Function
---
FOR --- 512
The instructions between FOR(512) and
NEXT(513) are repeated a specified number of
times.
NEXT --- 513
Symbol
FOR NEXT
Area
Function block
definitions
Block program areas Step program areas Subroutines Interrupt tasks
SFC action or
transition programs
Usage OK Not allowed OK OK OK OK
Operand Description Data type Size
N Number of loops UINT 1
Area
Word addresses
Indirect DM/EM
addresses
Con-
stants
Registers Flags
Pulse
bits
TR
bits
CIO WR HR AR T C DM EM
@DM
@EM
*DM
*EM
DR IR
Indirect
using IR
TK CF
N OK OK OK OK OK OK OK OK OK OK OK OK --- OK --- --- --- ---
Name Label Operation
Error Flag ER • ON if more than 15 loops are nested.
• OFF in all other cases.
Equals Flag = OFF
Negative Flag N OFF
The instructions between FOR(512) and NEXT(513)
are executed N times and then program execution
continues with the instruction after NEXT(513). The
BREAK(514) instruction can be used to cancel the
loop.
If N is set to 0, the instructions between FOR(512) and
NEXT(513) are processed as NOP(000) instructions.
Loops can be used to process tables of data with a
minimum amount of programming.
FOR(512)
N
N: Number of loops
NEXT(513)
Repeated N times
Repeated program section