Ternary conditional operator
In computer programming, the ternary conditional operator is a ternary operator that evaluates to one of two values based on a Boolean expression. The operator is also known as conditional operator, ternary if, immediate if, or inline if (iif). Although many ternary operators are theoretically possible, the conditional operator is commonly used and other ternary operators rare, so the conditional variant is commonly referred to as the ternary operator.
Typical syntax for an expression using the operator is like if a then b else c or a ? b : c. One can read it aloud as "if a then b otherwise c". The form a ? b : c is the most common, but alternative syntax exists. For example, Raku uses the syntax a ?? b !! c to avoid confusion with the infix operators ? and !, whereas in Visual Basic, it takes the form If(a, b, c).
The construct first appeared in CPL, in which equivalent syntax for a ? b : c is a → b, c.