Section 6.4 - Enumeration

Often a variable can have only one of a small set of values. An enumeration type can be created for such variables, making it easier to understand and permitting error detection. For example, let's say that a variable `Today' must be one of seven values, Monday through Sunday. Let's call the list of legal values type `Day', and set `Today' to Tuesday as an example:

 type Day is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
 subtype Weekday is Day range Monday .. Friday;
 subtype Weekend is Day range Saturday .. Sunday;
 -- ... some time later
 Today : Day;
 -- ... Here's an example of setting Today to a value.
 Today := Tuesday;

Here's a simplified BNF for declaring enumeration types:

 enumeration_type_declaration ::=
   "("  enumeration_literal_specification
      {  "," enumeration_literal_specification }  ")"

It happens that the Boolean type mentioned earlier is an Enumeration type with only two values - True and False.


There is no quiz question for this section.

You may go to the next section.


You may also:

PREVIOUS Go back to the previous section

OUTLINE  Go up to the outline of lesson 6

David A. Wheeler (dwheeler@dwheeler.com)

The master copy of this file is at "http://www.adahome.com/Tutorials/Lovelace/s6s4.htm".