repeat_until
Use the repeat_until loop to continue performing an action until conditions are true.
Operands
REPEAT
<statement>;
Structured Text
Operand | Type | Format | Enter |
bool_ expression | BOOL | Tag expression | BOOL tag or expression that evaluates to a BOOL value (BOOL expression) |
IMPORTANT:
- Do not iterate within the loop too many times in a single scan.
- The controller does not execute other statements in the routine until it completes the loop.
- A major fault occurs when completing the loop takes longer than the watchdog timer for the task.
- Consider using a different construct, such as if_then.
Description
The syntax is:

The following diagrams show how a repeat_until loop executes and how an exit statement
leaves the loop early.
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.

Affects Math Status Flags
No
Fault Conditions
A major fault will occur if: | Fault type | Fault code |
The construct loops too long | 6 | 1 |
Example 1
If performing 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; |
Provide Feedback