A conditional expression consists of a test and two branches. For instance, the following expression is conditional:
In order to assign a type T to a conditional expression, we need to assign the type bool to the test and the type T to both of the then-branch and the else-branch. For instance, the type int can be assigned to the above conditional expression if the name x is given the type int.
Suppose that we have a conditional expression that is well-typed. When evaluating it, we first evaluate the test to a value, which is guaranteed to be either true or false; if the value is true, then we continue to evaluate the then-branch; otherwise, we continue to evaluate the else-branch.
It is also allowed to form a conditional expression where the else-branch is missing or truncated. For instance, we can form an expression as follows: