[next] [previous] [contents]

  7.3 Creating Arrays Implicitly
  Create arrays implicitly as follows:

  .
        By referencing an element of an array that has not been
        explicitly declared
  .
        By using MAT statements

  When you first create an implicit array, the lower bound is
  zero and the upper bound is 10. An array created by refer-
  encing an element can have up to 32 dimensions in BASIC.
  An array created with a MAT statement can have only one
  or two dimensions.



                                            Note

        The ability to create arrays implicitly exists for com-
        patibility with previous implementations of BASIC.
        However, it is better programming practice to declare
        all arrays explicitly before using them.

  If you reference an element of an array that has not been
  explicitly declared, BASIC creates a new array with the name
  you specify. Arrays created by reference have default sub-
  scripts of (0 TO 10), (0 TO 10, 0 TO 10), (0 TO 10, 0 TO 10,
  0 TO 10), and so on, depending on the number of dimensions
  specified in the array reference. For example, the following
  program implicitly creates three arrays and assigns a value
  to one element of each:
  LET A(5,5,5) = 3.14159
  LET B%(3) = 33
  LET C$(2,2) = "Russell Scott"
  END

  The first LET statement creates an 11-by-11-by-11 ar-
  ray that stores floating-point numbers and assigns the value
  3.14159 to element (5,5,5). The second LET statement creates
  an 11-element list that stores integers and assigns the value
  33 to element (3), and the third LET statement creates an
  11-by-11 string array and assigns the value ``Russell Scott''
  to element (2,2).

  When you create an implicit numeric array by referring to
  an element, BASIC initializes all elements (except the one as-
  signed a value) to zero. For implicit string arrays, BASIC
  initializes all elements (except the one assigned a value) to a
  null string. When you implicitly create an array, you can-
  not specify a subscript greater than 10. An attempt to do so
  causes BASIC to signal ``Subscript out of range'' (ERR = 55),
  provided that subscript checking is enabled.

  Note that you cannot create an array implicitly, then redi-
  mension the array with an executable DIM statement. The
  DIM statement must execute before any reference to the
  array.

  An array name cannot appear in a declarative statement af-
  ter the array has been implicitly declared by a reference. The
  following DECLARE statement is therefore illegal and causes
  BASIC to signal the compile-time error ``illegal multiple
  definition of name NEW_ARRAY'':
  new_array (5,5,5) = 1
  DECLARE LONG new_array (15,10,5)