Creating an Array: Difference between revisions
Content added Content deleted
Line 48: | Line 48: | ||
You can also declare the size of the array and initialize the values at the same time: |
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 ); |
REF []INT more numbers = LOC [3]INT := ( 21, 14 ,63 ); |
||
[]INT sugared more |
[]INT sugared more cnumbers = ( 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. |
For Multi-Dimensional arrays you declare them the same except for a comma in the type declaration. |
||
The following creates a 3x2 int matrix |
The following creates a 3x2 int matrix |
||
REF [][]INT number matrix = LOC [3][2] INT; |
REF [][]INT number matrix = LOC [3][2] INT; |
||
[3,2]INT sugared number matrix1; # an matrix of integers # |
[3,2]INT sugared number matrix1; # an matrix of integers # |
||
[3][2]INT sugared number matrix2; # an array of arrays # |
[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 |
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. |
difference being each row in the matrix must be enclosed in its own braces. |
||
Line 65: | Line 66: | ||
FLEX [-10:10] INT flex balanced; |
FLEX [-10:10] INT flex balanced; |
||
This next piece of code creates an array of integers. The value of |
This next piece of code creates an array of integers. The value of |
||
each integer "pointed at" is the square of |
each integer "pointed at" is the square of it's index in the array. |
||
[-10:10] REF INT array of pointers to ints; |
[-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 |
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 # |
array of pointers to ints[index] := HEAP INT := i*i # allocate global memory # |
||
OD |
OD |
||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
AppleScript arrays are called lists: |
AppleScript arrays are called lists: |