Multidimensional Arrays

Multidimensional arrays are specified using multiple pairs of brackets, each pair specifying one dimension.

Integer[9][4] iScores

The above creates a two-dimensional array variable named iScores, with 9 rows of 4 columns each.

Individual array elements of a multidimensional array are accessed by typing the name of the variable followed by the indexer for each dimension in pairs of square brackets. Array dimensions are 0-based i.e. iValues[3][0] denotes the first element on the 4th row of a two-dimensional array. For example…

Integer[9][4] iScores

Integer iRow iCol

 

For iRow from 0 to 8

    For iCol from 0 to 3

        Move 1234 to iScores[iRow][iCol]

    Loop

Loop

Dynamic Multidimensional Arrays

Dynamic multidimensional arrays are declared by omitting the size of the most significant (leftmost) dimension, while specifying the size of the remaining dimensions.

Integer[][3] iColors

The above creates a two-dimensional dynamic array variable named iColors, containing an undefined number of elements of type Integer. Conceptually this represents a rectangular array with an undefined number of rows, each of 3 columns.

[0][0] [0][1] [0][2]

[1][0] [1][1] [1][2]

[2][0] [2][1] [2][2]

[…][0] […][1] […][2]

[n][0] [n][1] [n][2]

The most significant (leftmost) dimension of a dynamic multidimensional array grows as needed when individual elements are accessed. The remaining dimension have a fixed size, and cannot later be changed.

The specified size of each dimension does not need to be a constant, it can also be an expression computed at run-time. Except for when used to declare a struct member or a global(non-local) variable, where the size must be a constant computed at compile-time.

Static Multidimensional Arrays

Static multidimensional arrays are declared by specifying the size of all dimensions.

Integer[2][3] iScores

The above creates a two-dimensional static array variable named iScores, containing 2x3 number of elements of type Integer. Conceptually divided into 2 rows, each of 3 columns.

[0][0] [0][1] [0][2]

[1][0] [1][1] [1][2]

The specified size of each dimension does not need to be a constant, it can also be an expression computed at run-time. Except for when used to declare a struct member or a global(non-local) variable, where the size must be a constant computed at compile-time.

Jagged Arrays

You can create dynamic multidimensional arrays that are non-rectangular. Jagged arrays are conceptually and syntactically similar to dynamic multidimensional arrays, where all dimensions are dynamic. For example…

Integer[][] iValues

The above declares a two-dimensional jagged array variable named iValues, containing an undefined number of elements of type Integer. Conceptually this represents a structure containing an undefined number of rows, each row containing an undefined number of columns. Where each row can have different number of columns.

In contrast with regular multidimensional arrays, which are rectangular, jagged arrays are non-rectangular. For example, it's possible to have 1 column in the first row, and three columns in the second row.

[0][0]

[1][0] [1][1] [1][2]

[2][0] [2][1]

[3][0]

[4][0] [4][1] [4][2] [4][3]

Array Functions

A number of array functions for handling many typical array-specific tasks, such as searching for array elements, removing or adding new blank elements to dynamic arrays.

Web Applications

Multidimensional arrays are not supported as web properties, but they can be used as a member of a struct.

 

See Also

Static vs. Dynamic vs. Jagged Arrays