Enumerated types
Enumerated data types are user-defined data types. They allow values to be specified in a list.
Only assignment operators and relational operators are permitted on enumerated data type.
Enumerated data types can be declared as follows −
type
enum-identifier = (item1, item2, item3, ... )
Following are some examples of enumerated type declarations −
type
SUMMER = (April, May, June, July, September);
COLORS = (Red, Green, Blue, Yellow, Magenta, Cyan, Black, White);
TRANSPORT = (Bus, Train, Airplane, Ship);
The order in which the items are listed in the domain of an enumerated type defines the order of
the items. For example, in the enumerated type SUMMER, April comes before May, May comes
before June, and so on. The domain of enumerated type identifiers cannot consist of numeric or
character constants.
Subrange Types
Subrange types allow a variable to assume values that lie within a certain range. For example,
if the age of voters should lie between 18 to 100 years, a variable named age could be declared
as −
var
age: 18 ... 100;
We will look at variable declaration in detail in the next section. You can also define a subrange
type using the type declaration. Syntax for declaring a subrange type is as follows −
type
subrange-identifier = lower-limit ... upper-limit;
Following are some examples of subrange type declarations −
const
P = 18;
Q = 90;
type
Number = 1 ... 100;
Value = P ... Q;
Subrange types can be created from a subset of an already defined enumerated type, For
example −
type
months = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
Summer = Apr ... Aug;
Winter = Oct ... Dec;