REPEAT Statement

Help Contents

Introduction

The IEC 61131-3 ST REPEAT statement executes a list of statements until a condition is true. The REPEAT Statement has this syntax:

REPEAT
    Statement;
    Statement;
    ..
    Statement;
UNTIL Condition END_REPEAT;

Where:

The statements inside the REPEAT loop are executed until the condition becomes true.

The list of statements inside the REPEAT statement will always be executed at least once.

To stop the REPEAT loop early (before the condition becomes true) use the EXIT Statement.

Repeat Loop Flow Diagram

The flow diagram of the IEC 61131-3 Structured Text REPEAT statement

The REPEAT Loop uses this logic to execute statements:

  1. The statements (B) inside the loop are executed in order.
  2. The condition (A) is evaluated.
  3. If the condition (A) is FALSE, execution goes back to step 1.
  4. Otherwise the condition (A) is TRUE and the loop is complete.

Examples

  1. Repeat a block of statements until a condition is TRUE:
    Index := 0;
    Sum := 0;
    REPEAT
        Sum := Sum + Values[ Index ];
        Index := Index + 1;
    UNTIL Index >= 10 END_REPEAT;

Standards Compliance

IEC 61131-3 Second Edition: Table 56.8.

IEC 61131-3 Third Edition: Table 72.8.

Further Information

WHILE loop

For information about another loop type that uses a condition.

FOR loop

For information about another loop type that uses a fixed number of iterations.

Structured Text

For other Structured Text (ST) statement types.

Expressions

To learn about expressions that can be used as the condition in a REPEAT loop.

Glossary

For the meaning of terms used in Fernhill SCADA.