English
Language : 

NSB8 Datasheet, PDF (87/158 Pages) List of Unclassifed Manufacturers – BASIC interpreter for Z80 family
ITALIAN TECHNOLOGY
USING ARRAYS
grifo®
INDEXING AND SUBSCRIPTING
An array is an ordered collection of numeric variables. The entire array, as a whole, has a single
variable name, and all the variables (called elements) in the array share that name, much as the
members of a typical family share the same surname. An individual element in an array is identified
by its unique index number, which denotes its position in the ordering of the array elements. For the
convenience of both those who prefer counting from zero and those who prefer counting from one,
an extra element, the zero element, is included in each array. For example, a 50 element array, having
a maximum index number of 50, actually has 51 elements, indexed 0, 1, 2, …, 49, 50.
To represent a given array element in a numeric expression, you must follow the name of the array
with a subscript, the index number of the desired element enclosed in parentheses. For example, the
zero element of array A would be written as A(0), the eighth element as A(8), etc.
The index in a subscript may take the form of any numeric expression, it need not merely be a
constant. Therefore, if the simple variable I contains the value of 4, then A(I) will represent the same
element as A(4). Care should be taken, however, to make sure that any expression used as an array
index will not evaluate to a negative number or a number greater than the maximum index of the given
array. If either of these things happens, an OUT OF BOUNDS ERROR will occur. If the index
evaluates to a non integer, BASIC will truncate the value to an integer (truncation involves throwing
away the fractional part of a number and keeping only the whole part. The number 3.6 would be
truncated to the whole number 3. Note that this is not the same as rounding).
Note that the simple variable A and an array A may coexist in the same program without in any way
affecting each other. Arrays and simple variables with the same names are separate, distinct
entities. BASIC does not confuse the two, since a simple variable name will never be followed by
a subscript, while the name of an array must always be followed by one.
MULTIPLE DIMENSION ARRAYS
Arrays which require only one index may be thought of as single rows of variables. BASIC also
permits the definition of arrays which use more than one index in their subscripts. The addition of
each new index to an array is said to add another dimension to the array, and an array with n indices
is called an n dimensional array. When using more than one index to reference a single element, the
indices must be separated by commas. Remember that each index is allowed to be a numeric
expression.
To access the third element in the fifth row of a two dimensional array M, for example, you write
M(5,3). Assuming M has a maximum row number of X and a greatest column index of Y, the
following statements will list the contents of each element in the array in an appropriate tabular
format:
10 FOR I=0 TO X
20 FOR J=0 TO Y
25
REM Print next element w/no <CR>
30
PRINT TAB (I*15) , M (I,J),
35
REM Each column of numbers
36
REM is 15 spaces wide.
40 NEXT
NSB8
Rel. 5.10
Page 75