Arrays

Arrays

An array is a collection of string or integer values used by a program. Array indices are accessed through parentheses. Array indices start at 1 and end at the length of an array (for example, MyArray(3) returns the value in the third location of the variable array). One- and two-dimensional arrays are allowed. Two-dimensional arrays are referenced with two indices in parentheses, separated by a comma.
Arrays must be allocated through the use of the
DECLARE
command. Arrays can be re-dimensioned by using
DECLARE
, however, this will replace the original array.
Array size is limited only by the size of the memory available.
Format
DECLARE STRING <ARRAYNAME$>(<SIZE>)
DECLARE STRING <ARRAYNAME$>(<ROWS>,<COLUMNS>)
DECLARE NUMERIC <ARRAYNAME>(<SIZE>)
DECLARE NUMERIC <ARRAYNAME>(<ROWS>,<COLUMNS>)
Parameters
<SIZE> = number of entries in a single dimension array
<ROWS> = number of rows in a two dimensional array
<COLUMNS> = number of columns in a two dimensional array
Example
An example of
ARRAY
code is:
10 DECLARE STRING INARRAY$(3) 20 FOR I = 1 TO 3 30 PRINT "Name "; I; ": "; 40 INPUT INARRAY$(I) 50 NEXT I 60 PRINT INARRAY$(1); ", "; INARRAY$(2); ", and "; INARRAY$(3); 70 PRINT " went to the park" RUN Name 1: Jim Name 2: Jose Name 3: Jack Jim, Jose, and Jack went to the park
Comments
If you attempt to access an array outside of its allocated bounds, an error will occur.