IF Statement

Help Contents

Introduction

The IEC 61131-3 ST IF statement executes a list of statements depending on a condition. The IF statement has this syntax:

IF condition THEN
    Statement;
    ..
    Statement;
[ ELSEIF condition THEN
    Statement;
    ..
    Statement; ]
[ ELSE
    Statement;
    ..
    Statement; ]
END_IF;

Where:

The condition associated with the first IF clause is evaluated, and if the result is true, the statements immediately following the condition are executed. If the result of the condition is false, conditions associated with ELSEIF clauses are tried until one is found to be true. If the conditions are false, the statements in any ELSE clause are executed.

The ELSEIF and ELSE clauses are optional.

Examples

  1. Compare a variable against limits:
    IF Level <= 2.0 THEN
        State := "Normal";
    ELSEIF Level <= 3.5 THEN
        State := "High";
    ELSE
        State := "Overflow";
    END_IF

Standards Compliance

IEC 61131-3 Second Edition: Table 56.4.

IEC 61131-3 Third Edition: Table 72.4.

Further Information

Structured Text

For other Structured Text (ST) statement types.

Expressions

To learn about expressions that can be used as condition values.

Glossary

For the meaning of terms used in Fernhill SCADA.