For--Next Loop Instructions - Siemens SIMATIC S7-200 System Manual

Programmable controller
Hide thumbs Also See for SIMATIC S7-200:
Table of Contents

Advertisement

For- -Next Loop Instructions
Use the For (FOR) and Next (NEXT) instructions to
delineate a loop that is repeated for the specified count.
Each For instruction requires a Next instruction. You can
nest For--Next loops (place a For--Next loop within a
For--Next loop) to a depth of eight.
The For instruction executes the instructions between the
For and the Next instructions. You specify the index value or
current loop count INDX, the starting value INIT, and the
ending value FINAL.
The Next instruction marks the end of the FOR loop.
Error conditions that set ENO = 0
H 0006 (indirect address)
If you enable the For--Next loop, it continues the looping
process until it finishes the iterations, unless you change the
final value from within the loop itself. You can change the
values while the For--Next loop is in the looping process.
When the loop is enabled again, it copies the initial value
into the index value (current loop number).
The For--Next instruction resets itself the next time it is
enabled.
For example, given an INIT value of 1 and a FINAL value of 10, the instructions between the For
instruction and the Next instruction are executed 10 times with the INDX value being incremented:
1, 2, 3, ...10.
If the starting value is greater than the final value, the loop is not executed. After each execution of
the instructions between the For instruction and the Next instruction, the INDX value is
incremented and the result is compared to the final value. If the INDX is greater than the final
value, the loop is terminated.
If the top of stack is 1 when your program enters the For--Next loop, then the top of stack will be 1
when your program exits the For--Next loop.
Table 6-57
Valid Operands for the For and Next Instructions
Inputs/Outputs
INDX
INIT, FINAL
Data Types
Operands
INT
IW, QW, VW, MW, SMW, SW, T, C, LW, AC, *VD, *LD, *AC
INT
VW, IW, QW, MW, SMW, SW, T, C, LW, AC, AIW, *VD, *LD, *AC,
Constant
S7-200 Instruction Set
Chapter 6
169

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents