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 />

To assign values to a two-dimensional array in the executable section,<br />

you can use two nested FOR statements to increment the two indices, as<br />

shown in the following example:<br />

CON~:>T Zf.~ ro :::: ;<br />

VAR Table: ARRAY [1 •• 10,1 •• 5J OF INTEGER;<br />

i n (.l f:·~ >~ .... 1 , i :1".' (i (.:~ >( .... 2 : I NT E G E R ;<br />

BEGIN<br />

F (] F~ i n d f:~ ~.( .... 1 : :::: :I. T () :l ° DO<br />

FOR index_2 := :l TO 5 DO<br />

Table[index_:l,index_2] := Zero;<br />

END~<br />

Array_Example is :lefined to be a two-dimensional array of type<br />

INTEGER.<br />

The nested FOR statements assign the value of Zero (which has been<br />

assigned the value of "0" in the CaNST section) to each component in<br />

the array.<br />

To initialize a two-dimensional array in the VAR section, specify a<br />

constructor for each row, in parentheses. The following example shows<br />

a two-dimensional array that is initialized in the VAR section:<br />

VAR Table ARRAY [1 •• 10,1 •• 5] OF INTEGER := (10 OF (5 OF 0»;<br />

To assign values to arrays of three or more dimensions in the<br />

executable section, use three or more nested FOR statements:<br />

CONST Zero:::: 0,<br />

VAR Table: ARRAY [1 •• 5,1 •• 3,1 •• 2J OF INTEGER,<br />

index_l"index_2,index_3 : INTEGER;<br />

BEGIN<br />

FOR index_1 := 1 TO 5 DO<br />

FOR index_2 := 1 TO 3 DO<br />

FOR index_3 := 1 TO 2 DO<br />

TableCindex_l,index_2] := Zero;<br />

END;<br />

This example shows the initialization of a<br />

The value of· Zero is assigned to each<br />

Table[l,l,l] to Table(5,3,2].<br />

three-dimensional array.<br />

element in Table, from<br />

To initialize an array of three or more dimensions in the VAR section,<br />

specify a constructor for each row. The following example shows a<br />

three-dimensional array being initialized in the VAR section~<br />

VAR Table: ARRAY [1 •• 5,1 •• 3,1 •• 2] OF INTEGER :=<br />

(5 OF (3 OF (2 OF ' '»);<br />

2-13

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

Saved successfully!

Ooh no, something went wrong!