If … then … else (? :)
One value or another, depending on a test.
Syntax
test ? then : else
| Argument | Meaning |
|---|---|
| test | TRUE or FALSE. |
| then | The value when the test is TRUE. |
| else | The value when it is FALSE. |
Result
Whichever value the test chooses.
Examples
In the example drawing:
| Expression | Gives |
|---|---|
L>W?L:W |
500 |
1>2?"yes":"no" |
"no" |
L>600?3:(L>400?2:1) |
2 |
Notes
Only the value chosen is worked out. To choose from more than two, put the later choice in brackets, as in
L>600?3:(L>400?2:1): without them, a?b:c?d:e is read as (a?b:c)?d:e.