Attention

IronPLC can only run very simple programs. The steps described are accurate but many language features are not yet supported.

WHILE

The WHILE statement repeatedly executes a statement list as long as a boolean expression is TRUE.

IEC 61131-3

Section 3.3.2.4

Support

Supported

Syntax

WHILE expression DO
    statement_list
END_WHILE ;

Description

The WHILE loop evaluates the boolean expression before each iteration. If the expression is TRUE, the statement list executes and the expression is evaluated again. If the expression is FALSE on the first evaluation, the statement list never executes.

Example

PROGRAM main
    VAR
        count : INT := 10;
        total : INT := 0;
    END_VAR

    WHILE count > 0 DO
        total := total + count;
        count := count - 1;
    END_WHILE;
END_PROGRAM

See Also

  • FOR — counted loop

  • REPEAT — post-tested loop

  • EXIT — break from innermost loop