486 Rockwell Automation Publication 1756-RM003N-EN-P - October 2011
Chapter 12 For/Break Instructions (FOR, FOR...DO, BRK, EXIT, RET)
For (FOR)
The FOR instruction executes a routine repeatedly.
Operands:
Relay Ladder
Structured Text
Use the FOR...DO construct. See Structured Text Programming for information
on structured text constructs.
Description:
When enabled, the FOR instruction repeatedly executes the Routine until the
Index value exceeds the Terminal value. This instruction does not pass parameters
to the routine.
Each time the FOR instruction executes the routine, it adds the Step size to the
Index.
Be careful not to loop too many times in a single scan. An excessive number of
repetitions can cause the controller’s watchdog to timeout, which causes a major
fault.
Operand Type Format Description
Routine name ROUTINE Routine Name Routine to execute
Index DINT Tag Counts how many times the routine has been
executed
Initial value SINT
INT
DINT
Immediate
Tag
Value at which to start the index
Terminal value SINT
INT
DINT
Immediate
Tag
Value at which to stop executing the routine
Step size SINT
INT
DINT
Immediate
Tag
Amount to add to the index each time the FOR
instruction executes the routine
FOR count:= initial_value TO
final_value BY increment DO
<statement>;
END_FOR;
Do not use a FOR instruction to call (execute) the main routine.
· You can put a FOR instruction in the main routine or
any other routine.
· If you use a FOR instruction to call the main routine
and then put a RET instruction in the main routine, a
major fault occurs (type 4, code 31).