IF instructionΒΆ

With the IF instruction you can check a condition and, depending upon this condition, execute instructions.

Syntax:

IF <Boolean_expression1> THEN
    <IF_instructions>
{ELSIF <Boolean_expression2> THEN
    <ELSIF_instructions1>
.
.
ELSIF <Boolean_expression n> THEN
    <ELSIF_instructions n-1>
ELSE
<ELSE_instructions>}
END_IF;

The part in braces {} is optional.

If the <Boolean_expression1> returns TRUE, then only the <IF_Instructions> are executed and none of the other instructions.

Otherwise the Boolean expressions, beginning with <Boolean_expression2>, are evaluated one after the other until one of the expressions returns TRUE. Then only those instructions after this Boolean expression and before the next ELSE or ELSIF are evaluated.

If none of the Boolean expressions produce TRUE, then only the <ELSE_instructions> are evaluated.

Example:

IF temp<17
THEN heating_on := TRUE;
ELSE heating_on := FALSE;
END_IF;

Here the heating is turned on when the temperature sinks below 17 degrees. Otherwise it remains off.