694 Rockwell Automation Publication 1756-RM003N-EN-P - October 2011
Appendix C Structured Text Programming
The following diagrams show how a REPEAT...UNTIL loop executes and how
an EXIT statement leaves the loop early.
Arithmetic Status Flags: Not affected
Fault Conditions:
Example 1:
While the bool_expression is false, the controller
executes only the statements within the REPEAT…UNTIL
loop.
To stop the loop before the conditions are false, use an EXIT
statement.
Statement 1
Statement 2
Statement 3
Statement 4
…
BOOL expression
False
True
Rest Of The Routine
BOOL expression
False
True
Rest Of The Routine
Statement 1
Statement 2
Statement 3
statement 4
…
Exit ?
Yes
No
A major fault will occur if Fault type Fault code
The construct loops too long 6 1
If you want this Enter this structured text
The REPEAT...UNTIL loop executes the statements in the construct
and then determines if the conditions are true before executing the
statements again.
This differs from the WHILE...DO loop because the WHILE...DO The
WHILE...DO loop evaluates its conditions first. If the conditions are
true, the controller then executes the statements within the loop. The
statements in a REPEAT...UNTIL loop are always executed at least
once. The statements in a WHILE...DO loop might never be executed.
pos := -1;
REPEAT
pos := pos + 2;
UNTIL ((pos = 101) OR (structarray[pos].value = targetvalue))
end_repeat;