IF-THEN-ELSIF-ELSE-END_IF Statement

The ELSE and ELSIF statements are optional. If the ELSE statement is not written, no instruction is executed when the condition is FALSE. The ELSIF statement can be used more than once. The ELSE statement, if used, must appear only once at the end of the ‘IF, ELSIF...’ sequence.
IF-THEN-ELSIF-ELSE-END_IF Statement
Name
IF ... THEN ... ELSIF ... THEN ... ELSE ... END_IF
Meaning
executes one of several lists of Structured Text (ST) statements selection is made according to the value of a Boolean expression
Syntax
IF <Boolean_expression> THEN <statement> ; <statement> ; ... ELSIF <Boolean_expression> THEN <statement> ; <statement> ; ... ELSE <statement> ; <statement> ; ... END_IF;
AADvance-Trusted SIS Workstation software®
evaluates complete Boolean expressions. For instance, evaluating the following line of code, where i represents the array index having a definition of 2..10, causes a run-time error upon reaching the second part where it applies the value 1 as the array index.
IF i >= 2 and i <= 10 and Array1[i] > 5 THEN
To avoid this type of error, use the following code:
IF i >= 2 and i <= 10 THEN
IF Array1[i] THEN
Example
(* ST program using IF statement *) IF manual AND not (alarm) THEN level := manual_level; bx126 := bi12 OR bi45; ELSIF over_mode THEN level := max_level; ELSE level := (lv16 * 100) / scale; END_IF; (* IF structure without ELSE *) If overflow THEN alarm_level := true; END_IF;
To insert an IF-THEN-ELSIF-ELSE-END_IF statement
  • From the
    Toolbox
    , drag the
    IF THEN ELSE
    element into the language container.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal