Content deleted Content added
Tags: Reverted Visual edit |
Undid revision 1199190776 by 103.172.197.182 (talk) |
||
Line 200:
Subranges of any [[ordinal data type]] (any simple type except real) can also be made:
:<syntaxhighlight lang="pascal">▼
var▼
x : 1..10;▼
y : 'a'..'z';▼
===Set types===
Line 222 ⟶ 226:
if (i > 4) and (i < 11) then ...
</syntaxhighlight>
▲<syntaxhighlight lang="pascal">
▲var
▲ x : 1..10;
▲ y : 'a'..'z';
</syntaxhighlight>Sets of non-contiguous values can be particularly useful, in terms of both performance and readability:▼
▲
:<syntaxhighlight lang="pascal">
if i in [0..3, 7, 9, 12..15] then ...▼
</syntaxhighlight>
For these examples, which involve sets over small domains, the improved performance is usually achieved by the compiler representing set variables as [[bit vector]]s. The set [[Operator (programming)|operators]] can then be implemented efficiently as bitwise machine code operations.
===Record types===
▲<syntaxhighlight lang="pascal">
▲if i in [0..3, 7, 9, 12..15] then ...
</syntaxhighlight>An example of a Pascal record type:▼
:<syntaxhighlight lang="pascal">
type
car = record
length: integer;
width: integer
end;
</syntaxhighlight>
An example of a variant record type:
|