REPEAT Statement

Help Contents

Introduction

The Structured Text 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.

Example

Index := 0;
Sum := 0;
REPEAT
    Sum := Sum + Values[ Index ];
    Index := Index + 1;
UNTIL Index >= 10 END_REPEAT;

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.