ENUMERATED DATA TYPES
Enumerated variables are defined by the programmer. It allows you to create your own data types, which consist of a set of symbols. You first create the set of symbols, and assign to them a new data type variable name.

Having done this, the next step is to create working variables to be of the same type. The following portions of code describe how to create enumerated variables.


	type  civil_servant = ( clerk, police_officer, teacher, mayor );
	var   job, office : civil_servant;

The new data type created is civil_servant. It is a set of values, enclosed by the ( ) parenthesis. These set of values are the only ones which variables of type civil_servant can assume or be assigned.

The next line declares two working variables, job and office, to be of the new data type civil_servant.

The following assignments are valid,


	job := mayor;
	office := teacher;

	if office = mayor then writeln('Hello mayor!');

The list of values or symbols between the parenthesis is an ordered set of values. The first symbol in the set has an ordinal value of zero, and each successive symbol has a value of one greater than its predecessor.

	police_officer < teacher
evaluates as true, because police_officer occurs before teacher in the set.


MORE EXAMPLES ON ENUMERATED DATA TYPES

	type beverage = ( coffee, tea, cola, soda, milk, water );
	     color    = ( green, red, yellow, blue, black, white );
	var  drink : beverage;
	     chair : color;

	drink := coffee;
	chair := green;

	if chair = yellow then drink := tea;


Copyright B Brown/P Henry/CIT, 1988-1997. All rights reserved.

1