2 Instruction Descriptions
2-76
NJ-series Instructions Reference Manual (W502)
FOR and NEXT
*1 If you omit an input parameter, the default value is not applied. A building error will occur.
*2 If you omit the input parameter in a ladder diagram, the default value is not applied. A building error will occur. If you omit
the input parameter in ST, a default value of 1 is applied.
FOR: Marks the starting position for repeat processing and specifies the repeat condition.
NEXT: Marks the ending position for repeat processing.
Instruction Name FB/FUN Graphic expression ST expression
FOR Repeat Start FUN FOR Index:=InitVal TO End-
Val BY StepVal DO
expression
END_FOR*;
* In ST, do not use NEXT to
mark the ending position
of repeat processing. Use
END_FOR instead.
NEXT Repeat End FUN
Variables
Name Meaning I/O Description Valid range Unit Default
InitVal Initial value
Input
Value to set the Index to
when repetition is started.
Depends on data type.
---
*1
EndVal End value Value of Index where repeti-
tion is stopped
StepVal Increment Value to add to Index each
time processing is repeated
Depends on the data
type (but 0 is not
allowed)
*2
Index Control
variable
Output Loop index Depends on data type. --- ---
Boolean
Bit strings Integers
Real
numbers
Times, durations,
dates, and text strings
BOOL
BYTE
WORD
DWORD
LWORD
USINT
UINT
UDINT
ULINT
SINT
INT
DINT
LINT
REAL
LREAL
TIME
DATE
TOD
DT
STRING
InitVal OKOKOKOKOKOKOKOK
EndVal Must be the same data type as InitVal.
StepVal Must be the same data type as InitVal.
Index Must be the same data type as InitVal.
FOR
EN ENO
InitVal Index
EndVal
StepVal
NEXT
EN ENO