OR_ELSE
The operator is an extension of the IEC 61131-3 standard.
The operator OR_ELSE is only allowed for programming in Structured Text: OR operation of operands of type BOOL and BIT, with short-circuit evaluation.
This means:
If at least one of the operands is TRUE, the result of the operation is also TRUE, otherwise it is FALSE.
In contrast to using the IEC operator OR, with OR_ELSE the expressions for all further operands are no longer executed, if one of the operands was evaluated with TRUE.
Example:
Function_Block FB_Sample
VAR
nCounter : INT;
END_VAR
METHOD TestMethod : BOOL
nCounter := nCounter + 1;
TestMethod := TRUE;
PROGRAM MAIN
VAR
fbSampleOr : FB_Sample;
fbSampleOrElse : FB_Sample;
bResult : BOOL;
bVar : BOOL;
END_VAR
bResult : bVar OR fbSampleOr.TestMethod();
// Counter of fbSampleOr increases as the method is executed
bResult := bVar OR_ELSE fbSampleOrElse.TestMethod();
//Counter of fbSampleOrElse does not increases as the method is not executed
bVar is TRUE, therefore the result bResult is also TRUE when using both OR and OR_ELSE.
The difference between the two logical operators is that the second operand (the calling of the method) is only executed when using OR. In this case the counter of the function block instance fbSampleOr is incremented.
Since the first operand bVar1 is already yielding TRUE, the second operand is no longer executed when using OR_ELSE, therefore the method of the function block instance fbSampleOrElse is not called and the counter is not incremented.
See also: