next up previous contents index
Next: Initialization Up: Arrays Previous: Arrays   Contents   Index

Declaring and Defining Arrays

Arrays must be declared either by initial assignment, or by a line consisting of the array name followed by square-bracketed indices representing the maximum index in each dimension. In each case, the number of comma-separated indices sets the dimensionality of the array. In the initial declaration, the indices must be integers and not expressions. Indices are 0-based.

Examples

x[2, 4]
# This defines an array x: five blocks of three values

x[2, 4] = some_expression
# This likewise defines the array, and additionally sets
# the highest index to the result of an expression

Note that the numbers in the declaration are not sizes, but maximum values. This is different than C. Once an array has been defined, subsequent use allows expressions as the index values.



Stephen R. Whiteley 2022-05-28