IF Expressions [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation
SPL to HP C/XL Migration Guide
IF Expressions
Table 5-27. IF Expressions
---------------------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------------------
| | |
| if-expression: | conditional-expression: |
| | |
| IF condition-clause THEN true-expression | condition-clause ? true-expression |
| ELSE false-expression | : false-expression |
| | |
---------------------------------------------------------------------------------------------------------
| | |
| Example: | Example: |
| | |
| X + (IF A < B THEN 5 ELSE 6) | X + (A < B ? 5 : 6) |
| | |
---------------------------------------------------------------------------------------------------------
| |
| In both cases above, the expression evaluates to X+5 if the condition clause "A < B" |
| is true; otherwise, it evaluates to X+6. |
| |
---------------------------------------------------------------------------------------------------------
| | |
| An IF expression may be used in any | Same as SPL. |
| expression where the value of the result is | |
| allowed. | |
| | |
---------------------------------------------------------------------------------------------------------
The HP C/XL syntax may look cryptic to SPL programmers. It can be
beneficial to add parentheses to make the sections stand out, such as:
X + ( (A < B) ? ( 5 ) : ( 6 ) )
The HP C/XL "? :" conditional expression has lower precedence than "||"
(logical OR) and higher precedence than "=" (assignment).
MPE/iX 5.0 Documentation