next up previous contents index
Next: Derived Types Up: Data Types Previous: Base Types

Enumerated Types

 

An enumerated type is a user-defined set of integral values. Each element of an enumerated type is given a unique identifier (by the user) and a unique value. By default, the values of an enumerated type are consecutive starting at 0. Thus, it is legal to iterate from one element to another, as shown below.

    type fruit = (apple, banana, orange, mango);

    var f : fruit;

    for f := apple to orange do
       . . .
    end;
All operations that are legal on integral types are legal on enumerated types, except that the value of an enumerated type is limited to the set of values specified in the enumerated type's declaration.

The values of specific elements of an enumerated type may be specified in the type declaration. The following declaration would start the values at 171 instead of 0.

    type fruit = (apple=171, banana, orange, mango);
Any arbitrary integral expression can be used to define values of enumerated types. These expressions cannot refer to other values in the same set, so the following is illegal.

    type fruit = (apple=171, banana=apple+2, orange, mango);



Kay Nettle
Fri Feb 21 21:14:29 CST 1997