5.4 Case Statements
selects for execution one of a number of alternative sequences_of_statements
the chosen alternative is defined by the value of an expression.
Name Resolution Rules
The possible values of the expression
shall be covered as follows:
- Otherwise, each value of the base
range of the type of the expression
shall be covered (either explicitly or by others).
(the value is not covered by any discrete_choice_list
perhaps due to being outside the base range), Constraint_Error is raised.
4 The execution of a case_statement
chooses one and only one alternative. Qualification of the expression
of a case_statement
by a static subtype can often be used to limit the number of choices
that need be given explicitly.
Examples of case
case Sensor is
when Elevation => Record_Elevation(Sensor_Value);
when Azimuth => Record_Azimuth (Sensor_Value);
when Distance => Record_Distance (Sensor_Value);
when others => null;
case Today is
when Mon => Compute_Initial_Balance;
when Fri => Compute_Closing_Balance;
when Tue .. Thu => Generate_Report(Today);
when Sat .. Sun => null;
case Bin_Number(Count) is
when 1 => Update_Bin(1);
when 2 => Update_Bin(2);
when 3 | 4 =>
when others => raise Error;