Topic: DMD0102 IF - If / Else Expression |
|
|
|
This instruction can only be used in the Expression parameter of the Calculate Expression (MATH) instruction.
The 3-parameter If / Else Expression (IF) math function evaluates the first parameter to determine which of the following two parameters to process. If the first parameter is non-zero (TRUE, ON) the Result will be the value of the second parameter, If the first parameter is zero (FALSE, OFF) the Result will be the value of the third parameter.
The parameter list must consist of 3 parameters separated by commas. Each of the parameters is an expression, which can be a constant value, a bit or numeric memory location, an arithmetic expression, and/or mathematical function or other expressions up to a maximum of 1024 characters. Expressions can be nested, so use of parentheses is recommended to ensure proper evaluation order.
This function has the following three parameters:
In this example: if C0 is ON then D0 will contain the value of D1 else (C0 is OFF) D0 will contain the value of D2. |
|
|
|
If / Else Expression parameters can be nested, meaning that any or all of the three parameters in the If / Else Expression can be If / Else Expressions themselves as shown here:
In this example, if C0 is ON then If C6 is ON then D0 will contain the value of D1 else (C6 is OFF) D0 will contain the value of D2
else (C0 is OFF) If C7 is ON then D0 will contain the value of D3 else (C7 is OFF) D0 will contain the value of D4 |
|
|
|
Any or all of the three parameters can consist of expression combinations as show here:
In this example: if D1 is greater than D2 then D0 will contain the value of D1 - D2 else D2 is greater than D1 D0 will contain the value of D2 - D1 |
|
|
|
See Also:
|
|
|
|
Rung Example:
|
|
|