Enumerated types
Enumerated types allow a certain expression which can make your code easier to read.
An enumerated type consists of a list of values. These values are not strings and they don't take storage, rather they are like a set of constants to which the language automatically assigns a value.
Here is an example. Note that the names of the days are not surrounded by quotes (they are not strings)
An enumerated type consists of a list of values. These values are not strings and they don't take storage, rather they are like a set of constants to which the language automatically assigns a value.
Here is an example. Note that the names of the days are not surrounded by quotes (they are not strings)
type
Tdays = (Monday,Tuesday,Wednesday,Thursday,Friday);
You now have a bunch of rather unconventional constants which can be used in expressions
type
Tdays = (Monday,Tuesday,Wednesday,Thursday,Friday);
var
days : Tdays;
begin
for days := Monday to Thursday do
begin
writeln(ord(days));
end;
if ord(Thursday) = 3 then
writeln('true')
else
writeln('false');
readln;
end.
Notice that in order to actually use the values you'll need to convert the types by using the ord() function.
Logical (Bitwise) operators
Logical operators