Ternary Operator
The PSL ternary operator ?: behaves similarly to the C conditional expression in that it connects three operands and offers an alternative way of expressing a simple if...else statement. The format for the PSL conditional expression is as follows:
result = expression1 ? expression2 : expression3;
If expression1 is TRUE (nonzero), then expression2 is evaluated; otherwise, expression3 is evaluated. The value for the complete conditional expression is the value of either expression2 or expression3, depending on which expression was evaluated. The value of the expression may be assigned to a variable.
Conditional expressions are most useful in replacing short, simple if...else statements. For example, the if...else statement
if (x==1) {
y=10;
}
else {
y=20;
}
can be replaced with the following one-line conditional statement:
y = (x==1) ? 10 : 20;
These examples perform the same function. If x is 1, then y becomes 10 else y becomes 20.s
Where to go from here