ARRAYS An array represents an indexed collection of elements of the same type (called the base type). Because each element has a unique index, arrays, unlike sets, can meaningfully contain the same value more than once. Array types are denoted by constructions of the form: type[array_length] Each of the elements of an array is numbered from 0 through the array_length - 1. Every element of an array is of type and can be accessed by specifying array name followed by element’s index within brackets. Here are a few examples of array declaration: dim weekdays as byte[7] dim samples as word[50] begin ' Now we can access elements of array variables, for example: samples[0] = 1 if samples[37] = 0 then ... Constant Arrays Constant array is initialized by assigning it a comma-delimited sequence of values within parentheses. For example: ' Declare a constant array which holds no. of days in each month: const MONTHS as byte[12] = (31,28,31,30,31,30,31,31,30,31,30,31) ' Declare constant numbers: const NUMBER as byte[4][4] = ((0, 1, 2, 3), (5, 6, 7, 8), (9, 10, 11,12), (13,14, 15, 16)) Note that indexing is zero based; in the previous example, number of days in January is MONTHS[0], and number of days in December is MONTHS[11]. The number of assigned values must not exceed the specified length. Vice versa is possible, when the trailing “excess” elements will be assigned zeroes. For more information on arrays of char, refer to Strings. MULTI-DIMENSIONAL ARRAYS An array is one-dimensional if it is of scalar type. One-dimensional arrays are sometimes referred to as vectors. Multidimensional arrays are constructed by declaring arrays of array type. These arrays are stored in memory in such way that the right most subscript changes fastest, i.e. arrays are stored “in rows”. Here is a sample 2-dimensional array: dim m as byte[50][20] '2-dimensional array of size 50x20 Variable m is an array of 50 elements, which in turn are arrays of 20 bytes each. Thus, we have a matrix of 50x20 elements: first element is m[0][0], last one is m[49][19]. First element of the 5th row would be m[0][5]. If you are not initializing the array in the declaration, you can omit the first dimension of multi-dimensional array. In that case, array is located elsewhere, e.g. in another file. This is a commonly used technique when passing arrays as function parameters: sub procedure example(dim byref m as byte[50][20]) ' we can omit first dimension ... inc(m[1][1]) end sub dim m as byte[50][20] '2-dimensional array of size 50x20 dim n as byte[4][2][7] '3-dimensional array of size 4x2x7 main: ... func(m) end.