Creating an Array: Difference between revisions

m
Line 48:
You can also declare the size of the array and initialize the values at the same time:
REF []INT more numbers = LOC [3]INT := ( 21, 14 ,63 );
[]INT sugared more numberscnumbers = ( 21, 14 ,63 );
[3]INT sugared more vnumbers := ( 21, 14 ,63 );
For Multi-Dimensional arrays you declare them the same except for a comma in the type declaration.
The following creates a 3x2 int matrix
REF [][]INT number matrix = LOC [3][2] INT;
[3,2]INT sugared number matrix1; # an matrix of integers #
[3][2]INT sugared number matrix2; # an array of arrays of integers #
As with the previous examples you can also initialize the values of the array, the only
difference being each row in the matrix must be enclosed in its own braces.
Line 65 ⟶ 66:
FLEX [-10:10] INT flex balanced;
This next piece of code creates an array of integers. The value of
each integer "pointed at" is the square of itsit's index in the array.
[-10:10] REF INT array of pointers to ints;
FOR index FROM LWB array of pointers to ints TO UPB array of pointers to ints DO
array of pointers to ints[index] := HEAP INT := i*i # allocate global memory #
OD
 
=={{header|AppleScript}}==
AppleScript arrays are called lists: