next up previous contents index
Next: repeat Up: Control Structures Previous: if, elif, else   Contents   Index

ternary conditional

a ? b : c

The ternary conditional operation, familiar from the C programming language, is supported. In this construct, the `?' and `:' are literal, the a, b, and c are expressions. If a evaluates as true, then b is evaluated and the construct returns its result. Otherwise, c is evaluated and the construct returns that result. Hence, the form

x = a ? b : c

is equivalent to

if (a)
    x = b
    x = c

The ``true'' condition depends on the type of variable represented by a, as for the if operator. For example, the following are true:

Stephen R. Whiteley 2017-03-22