An array represents an indexed collection of elements of the same type. The array is characterized by its name, the type of stored items, the size (number of stored items) and the numbering of elements. An array can be viewed as a table:
In the table above N – an array size (number of items in the array). There is no limitation to the maximum array size, although using exceptionally large arrays is not recommended. All arrays are indexed from 1 up to array size.
Arrays can be used anywhere where simple variables of the same base type are legal. To access array item you need to specify array name and item index, index can be any numeric expression that doesn't violate the range bounds:
To define an array variable use the following syntax:
<Array variable name>: array <Array size> of <Array base type>
V: array 10 of Real ! Definition of an array of 10 real items
V = 10.67 ! Assigning value to the fifth array item
i = 7
! Using array in expressions
i = 7
V = 15*sqr((sin(V[i]))^2 + (cos(V[i+1]))^2)
An array with hardcoded number of elements is called a static array. An array whose size can change along the course of program execution is called dynamic array. To define a dynamic array omit the array size in the array definition. Dynamic arrays are indexed from 1. The size of dynamic array is set to the maximum item index that was accessed.
String arrays can only be of dynamic kind. The following is an example of string array definition and usage.
ArrayS: array of string ! Array definition
! Fill array items
ArrayS = "Hello," ! There is no need to specify
ArrayS = " World" ! the number of items
ArrayS = "!" ! the memory is allocated automatically
! Array use
output ArrayS + ArrayS + ArrayS