Retrieving an Element of an Array: Difference between revisions

(Modula-3)
Line 22:
</ada>
Monday_Sales is assigned 200
 
=={{header|ALGOL 68}}==
{{trans|FORTRAN}}
 
{{works with|ALGOL 68|Standard - no extensions to language used}}
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
[[ELLA ALGOL 68]] translator has restrictions on the number of dimensions and hence cannot compile this code.
<pre>
main:(
PROC get item = (REF [] INT array, INT index)INT:(
array[index]
);
[4]INT array := (222,444,666,888);
print((get item(array, 3), newline));
 
OP INIT = (REF[]REAL array)REF[]REAL:( FOR i FROM LWB array TO UPB array DO array[i]:=0.0 OD; array);
OP INIT = (REF[,]REAL array)REF[,]REAL:( FOR i FROM LWB array TO UPB array DO INIT array[i,] OD; array);
 
[-10:20]REAL a; INIT a; # a one-dimensional real array indexed from -10 to 20 #
REAL x, y, z;
[5,4]REAL p, q, r; INIT p; # two-dimensional arrays row-indexed from 1 to 5, column-indexed from 1 to 3 #
[2,3,2,2,3,4,2]REAL f; # a seven-dimensional array (max dimensions allowed is 7) #
x := a[-5]; # gets element at index -5 #
y := a[0]; # gets element at index 0 #
z := a[20]; # gets element at index 20 #
z := p[5,2]; # gets element in row 5, column 2 #
p := q; # gets all elements of Q into P #
p[:,2] := a[1:5]; # gets elements at indices 1 to 5 of A into the 2nd column of P #
 
# Note: ALGOL 68 does not have the concept of a slice with a stride #
 
r[1:4,] := p[2:5,]; # gets 4x4 subarray of P starting in 2nd row into 4x4 subarray of R starting in 1st row #
r[3:5,] := f[1,1,1,1,,,1] # gets a 3x4 subarray of F into a 3x4 subarray of R starting in row 3 #
 
)
</pre>
Output:
<pre>
+666
</pre>
 
=={{header|AppleScript}}==