| Line 29: |
Line 29: |
| | | | |
| | A major fault in the original definition of Pascal was the lack of string support. Namely, strings are packed arrays of chars, with minimal string-specific support. This shortcoming has been addressed by every modern Pascal compiler, which provide well-supported native string data types. | | A major fault in the original definition of Pascal was the lack of string support. Namely, strings are packed arrays of chars, with minimal string-specific support. This shortcoming has been addressed by every modern Pascal compiler, which provide well-supported native string data types. |
| | + | |
| | + | == Sets == |
| | + | |
| | + | In Pascal, a '''set''' is a collection of ordinal values of the same type. |
| | + | Operators can test for the existence of a value in a set ''and'' or ''or'' two sets together, compare sets, and do other operations. |
| | + | The following code shows an example of declaring and using a set, in this case of the days of the month that are Sundays. |
| | + | type |
| | + | DaysOfMonthSet = set of 1..31; {Declare type as a set representing the days of a month} |
| | + | |
| | + | |
| | + | procedure Demo; |
| | + | var SundaysInMonth: DaysOfMonthSet; {Declare variable of type DaysOfMonthSet} |
| | + | DaysWorked: DaysOfMonthSet; {And another} |
| | + | Day: Byte; {Declare 8-bit variable to hold a day of the month} |
| | + | begin |
| | + | SundaysInMonth:=[2,9,16,23,30]; {Allocate the 2nd, 9th, etc. of month to the set SundaysInMonth.} |
| | + | DaysWorked:=[10..14, 17..21]; {Allocate two ranges of dates to the set DaysWorked.} |
| | + | ... |
| | + | if Day in SundaysOfMonth {'in' operator tests for a value in a set.} |
| | + | then writeln('Day is a Sunday') |
| | + | else writeln('Day is not a Sunday'); |
| | + | ... |
| | + | if DaysWorked * SundaysInMonth = [] {* operator ''ands'' both sets together. '[]' is an empty set.} |
| | + | then writeln('No Sunday shifts worked.'); |
| | + | end |
| | | | |
| | ==References== | | ==References== |