NASutils Knowledge BaseUnofficialPolski

Pascal · lesson 18 of 30 · Data, functions and the command lineUse your own values

An enumeration names the days, a set holds some of them, in asks whether a day is there.

Programming on the NAS › Pascal in 30 lessons

18-enums-sets.pas Download 18-enums-sets.pas

program EnumsSets;
{$mode objfpc}{$H+}
type
  TDay = (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
  TDays = set of TDay;
const
  Backup: TDays = [Mon, Wed, Fri];
var
  Day: TDay;
begin
  for Day := Low(TDay) to High(TDay) do
    if Day in Backup then
      WriteLn(Day, ': backup')
    else if Day >= Sat then
      WriteLn(Day, ': free')
    else
      WriteLn(Day);
end.

Terminal

$ ./18-enums-sets
Mon: backup
Tue
Wed: backup
Thu
Fri: backup
Sat: free
Sun: free

Exercise

Make a second set for the days of a long test.