|
|||||
|
|||||
Related Concepts | |||||
control structure |
-> (conditional operator) |
Syntax
boolean-expression -> if-true-expression | if-false-expression
You can use the conditional operator ->...|...
to select one of two values based on a condition:
process local integer planet initial {3} output "Hello " || (planet = 3 -> "Human" | "Alien")
The conditional operator has low precedence and so will usually need to be included in parentheses when combined with other operators.
Two conditional expressions can be combined so that one is the argument of another:
process local integer planet initial {3} local switch morning initial {false} local switch dark-out initial {true} output "Good " || (morning -> "morning" | dark-out -> "evening" | "afternoon") || " " || (planet = 3 -> "Human" | "Alien")
The two alternative values must be of the same type. Implicit conversion of types through the invocation of conversion functions is not supported. However, you can explicitly cast a value to a new type:
process local integer x local integer y initial {77} local stream s initial {"234"} set x to (condition -> y | integer s)
The type of a conditional expression is the type of its arguments. If a different type is expected, implicit conversion will occur where supported by internal or user defined conversion functions.
If the alternative values are of record types, they may be different types as long as both types are extensions of the same base type.
Related Concepts Conditional constructs |