7.1 Overview of Arrays
A one-dimensional array is called a list or vector. A two-
dimensional array is called a matrix . BASIC arrays can
have up to 32 dimensions, and a specific type of BASIC ar-
rays can be redimensioned at run time. In addition, you can
specify the data type of the values in an array by using data
type keywords or suffixes.
The subscript of an element in an array defines that ele-
ment's position in the array. When you create an array, you
specify:
.
The number of dimensions that the array contains
.
The range of values for the subscripts in each dimension
of the array
BASIC arrays are zero-based by default; that is, when cal-
culating the number of elements in a dimension, you count
from zero to the number of elements specified. For example,
an array with an upper bound of 10 and no specified lower
bound has 11 elements: 0 to 10, inclusive. The array My_
array (3,3) has 16 elements: 0 to 3 in each dimension, or 4
2
.
BASIC also lets you specify a lower bound for any or all di-
mensions in an array, unless the array is a virtual array. By
specifying lower and upper bounds for arrays, you can make
your array subscripts meaningful. For example, the following
array contains sales information for the years 1990 to 1994:
DECLARE REAL Sales_data(1990 TO 1994)
To refer to an element in the array Sales_data , you need
only specify the year you are interested in. For example, to
print the information for the year 1992, you would type:
PRINT Sales_data(1992)
You can create arrays either implicitly or explicitly. You im-
plicitly create arrays having any number of dimensions by
referencing an element of the array. If you implicitly create
an array, BASIC sets the upper bound to 10 and the lower
bound to zero. Therefore, any array that you create implicitly
contains 11 elements in each dimension.
The following example refers to the array Student_grades .
If the array has not been previously declared, BASIC will
create a one-dimensional array with that name. The array
contains 11 elements.
Student_grades(8) = "B"
You create arrays explicitly by declaring them in a DIM,
DECLARE, COMMON, or MAP statement, or record decla-
ration. Note that if you want to specify lower bounds for your
array subscripts, you must declare the array explicitly.
When you declare an array explicitly, the value that you
give for the upper bound determines the maximum subscript
value in that dimension. If you specify a lower bound, then
that is the minimum subscript value in that dimension. If
you do not specify a lower bound, BASIC sets the lower bound
in that dimension to zero. You can specify bounds as either
positive or negative values. However, the lower bound of each
dimension must always be less than or equal to the upper
bound for that dimension.
You can use MAT statements to create and manipulate ar-
rays. However, MAT statements are valid only on arrays of
one or two dimensions. In addition, the lower bounds of all
dimensions in an array referenced in a MAT statement must
be zero.