Pascal (programming language): Difference between revisions

Content deleted Content added
Filled in 1 bare reference(s) with reFill 2
Tags: Reverted Visual edit
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';
</syntaxhighlight>
 
===Set types===
Line 226 ⟶ 222:
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:
 
:
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:
 
:
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: