IF Statement

Introduction

The Structured Text 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 all of the conditions are false, the statements in any ELSE clause are executed.

The ELSEIF and ELSE clauses are optional.

Example

IF Level <= 2.0 THEN
    State := "Normal";
ELSEIF Level <= 3.5 THEN
    State := "High";
ELSE
    State := "Overflow";
END_IF

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.