DocAda(tm) is a productivity tool of KSCE
|
|
|
| ![]()
About DocAda Light:
Preface / Preliminary
/ Help
/ TOC
/ Copyright
DocAda Online at the Ada Home:
Complete RM95
/ Updates
/ News
A case_statement selects for execution one of a number of alternative sequences_of_statements; the chosen alternative is defined by the value of an expression.
Syntax
case_statement ::=
case expression is
case_statement_alternative
{case_statement_alternative}
end case;
case_statement_alternative ::=
when discrete_choice_list =>
sequence_of_statements
Name Resolution Rules
The expression is expected to be of any discrete type. The expected type for each discrete_choice is the type of the expression.
Legality Rules
The expressions and discrete_ranges given as discrete_choices of a case_statement shall be static. A discrete_choice others, if present, shall appear alone and in the last discrete_choice_list.
The possible values of the expression shall be covered as follows:
Two distinct discrete_choices of a case_statement shall not cover the same value.
Dynamic Semantics
For the execution of a case_statement the expression is first evaluated.
If the value of the expression is covered by the discrete_choice_list of some case_statement_alternative, then the sequence_of_statements of the _alternative is executed.
Otherwise (the value is not covered by any discrete_choice_list, perhaps due to being outside the base range), Constraint_Error is raised.
Examples
Examples of case statements:
case Sensor is
when Elevation => Record_Elevation(Sensor_Value);
when Azimuth => Record_Azimuth (Sensor_Value);
when Distance => Record_Distance (Sensor_Value);
when others => null;
end case;
case Today is
when Mon => Compute_Initial_Balance;
when Fri => Compute_Closing_Balance;
when Tue .. Thu => Generate_Report(Today);
when Sat .. Sun => null;
end case;
case Bin_Number(Count) is
when 1 => Update_Bin(1);
when 2 => Update_Bin(2);
when 3 | 4 =>
Empty_Bin(1);
Empty_Bin(2);
when others => raise Error;
end case;
About DocAda Light:
Preface / Preliminary
/ Help
/ TOC
/ Copyright
DocAda Online at the Ada Home:
Complete RM95
/ Updates
/ News
|
|
|
| ![]()