4.5.7 Conditional Expressions
Syntax
Name Resolution Rules
A
condition
is expected to be of any boolean type.
Legality Rules
Dynamic Semantics
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.
Examples
Put_Line ("Casey is " &
(
if Casey.Sex = M
then "Male"
else "Female")); --
see 3.10.1
function Card_Color (Card : Suit)
return Color
is --
see 3.5.1
(
case Card
is
when Clubs | Spades => Black,
when Hearts | Diamonds => Red);
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe