31.12.2013 Views

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>PASCAL</strong> DATA TYPES<br />

2.3.1.5 Array Examples -<br />

Example 1<br />

TYPE Times = 1 •• 10;<br />

VAR Raceresults : ARRAY[1 •• 50J OF Times;<br />

I : I NTEGEfn<br />

BEGIN<br />

FOR I := 1 TO 50 DO<br />

Raceresults[IJ != 0<br />

END;<br />

This example decl~res the variable Raceresults as a 50-component array<br />

of Times. The FOR statement assigns zero to each component in the<br />

array.<br />

Example 2<br />

T Y P E f:) t, r i n 9 ,,: PAC KED A F~ RAY [1.. 1 () ] 0 F C H A FU<br />

VAR Composer, Word, Empt~ : String;<br />

BEGIN<br />

END;<br />

Word := 'engrossing';<br />

Composer := 'C.P.E.Bach';<br />

EITJPt~:J ::::: I<br />

This example declares three string variables. It assigns string<br />

constants to the variables Word and Composer, and assigns a string of<br />

10 spaces to the variable Empty.<br />

Example 3<br />

CONST Da\.~~:; :::: 31;<br />

TYPE Weather:::: (Rain, Snow, Sunn~, Cloud~, Fogg~);<br />

Month = ARRAY C1 •• DAYS] OF Weather;<br />

This example shows how you can use a constant identifier in the index<br />

type. The indices of arrays of type Month range from 1 to the value<br />

of the constant Days.<br />

2.3.2 Record Types<br />

The record is a convenient way to organize several related data items<br />

of different types. A record consists of one or more fields, each of<br />

which contains one or more data items. Unlike the components of an<br />

array, the fields of a record can be of different types. The record<br />

type definition specifies the name and type of each field.<br />

2-15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!