A conditional_expression
selects for evaluation at most one of the enclosed *dependent_*expressions,
depending on a decision among the alternatives. One kind of conditional_expression
is the if_expression,
which selects for evaluation a *dependent_*expression
depending on the value of one or more corresponding conditions. The other
kind of conditional_expression
is the case_expression,
which selects for evaluation one of a number of alternative *dependent_*expressions;
the chosen alternative is determined by the value of a *selecting_*expression.

if_expression ::=

**if** condition **then** *dependent_*expression

{**elsif** condition **then** *dependent_*expression}

[**else** *dependent_*expression]

{

[

case_expression ::=

**case** *selecting_*expression **is**

case_expression_alternative {,

case_expression_alternative}

case_expression_alternative {,

case_expression_alternative}

Wherever the Syntax Rules allow an expression,
a conditional_expression
may be used in place of the expression,
so long as it is immediately surrounded by parentheses.

If a conditional_expression
is expected to be of a type *T*, then each *dependent_*expression
of the conditional_expression
is expected to be of type *T*. Similarly, if a conditional_expression
is expected to be of some class of types, then each *dependent_*expression
of the conditional_expression
is subject to the same expectation. If a conditional_expression
shall resolve to be of a type *T*, then each *dependent_*expression
shall resolve to be of type *T*.

The possible types
of a conditional_expression
are further determined as follows:

If the conditional_expression
is the operand of a type conversion, the type of the conditional_expression
is the target type of the conversion; otherwise,

If all of the *dependent_*expressions
are of the same type, the type of the conditional_expression
is that type; otherwise,

If a *dependent_*expression
is of an elementary type, the type of the conditional_expression
shall be covered by that type; otherwise,

If the conditional_expression
is expected to be of type *T* or shall resolve to type *T*,
then the conditional_expression
is of type *T*.

A condition
is expected to be of any boolean type.

The expected type for the *selecting_*expression
and the discrete_choices
are as for case statements (see 5.4).

All of the *dependent_*expressions
shall be convertible (see 4.6) to the type
of the conditional_expression.

If the expected type of a conditional_expression
is a specific tagged type, all of the *dependent_*expressions
of the conditional_expression
shall be dynamically tagged, or none shall be dynamically tagged. In
this case, the conditional_expression
is dynamically tagged if all of the *dependent_*expressions
are dynamically tagged, is tag-indeterminate if all of the *dependent_*expressions
are tag-indeterminate, and is statically tagged otherwise.

All Legality Rules that apply to the discrete_choices
of a case_statement
(see 5.4) also apply to the discrete_choices
of a case_expression
except within an instance of a generic unit.

For the evaluation of an if_expression,
the condition
specified after **if**, and any conditions
specified after **elsif**, are evaluated in succession (treating a
final **else** as **elsif** True **then**), until one evaluates
to True or all conditions
are evaluated and yield False. If a condition
evaluates to True, the associated *dependent_*expression
is evaluated, converted to the type of the if_expression,
and the resulting value is the value of the if_expression.
Otherwise (when there is no **else** clause), the value of the if_expression
is True.

For the evaluation of a case_expression,
the *selecting_*expression
is first evaluated. If the value of the *selecting_*expression
is covered by the discrete_choice_list
of some case_expression_alternative,
then the *dependent_*expression
of the case_expression_alternative
is evaluated, converted to the type of the case_expression,
and the resulting value is the value of the case_expression.
Otherwise (the value is not covered by any discrete_choice_list,
perhaps due to being outside the base range), Constraint_Error is raised.

Ada 2005 and 2012 Editions sponsored in part by **Ada-Europe**