Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
ENUM.PAS
◄Example► ◄Contents► ◄Index► ◄Back►
PROGRAM enum;
{ ENUM.PAS demonstrates procedures and functions used with
enumerated types, including:
First Last Ord Pred Succ
}
TYPE
planets_t = (mercury, venus, earth, mars, jupiter, saturn, uranus,
neptune, pluto);
p_names = ARRAY[planets_t] OF STRING[7];
CONST
program_name = 'ENUM ';
program_desc = 'demonstrates enumerated types.';
planet_str : p_names = ('Mercury', 'Venus', 'Earth', 'Mars',
'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto');
VAR
planet : planets_t;
BEGIN
Writeln( program_name, program_desc );
Writeln;
Writeln( 'The planet nearest the sun is ',
planet_str[First( planets_t )], '.');
Writeln( 'The next planet is ',
planet_str[Succ( First( planets_t ) )], '.' );
{ Note that ORD of a type starts at 0; hence we add one. }
Writeln( 'Our planet is the ', Ord( earth ) + 1,
'rd planet from the sun.');
Writeln( planet_str[Pred( earth )], ' and ',
planet_str[Succ( earth )], ' are on either side of Earth.');
Writeln( 'Usually, the next-to-last planet from the sun is ',
planet_str[Pred( Last( planets_t ) )], '.');
Writeln( 'Usually, the farthest planet from the sun is ',
planet_str[Last( planets_t )], '.');
END.