Warning

You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

This is an old revision of the document!


Arrays

Arrays must be defined using the DIM statement. As of the current version, maximum two-dimensional arrays are supported and both dimensions are limited to a length of 32767 elements. However, this is just a theoretical limit, in practice you'll run out of memory earlier. Arrays are zero-based (the first index is 0) and only integers may be used as indices.

The syntax to define array is the following (note the square brackets):

dim variable[x_len, y_len]

Example:

dim myArr[100, 100]
let myArr[15, 2] = 3420
print myArr[15, 2]

Or:

rem ** fill an array with consecutive numbers **
dim myArr[10]
for i=0 to 9
  let myArr[i] = i
next i
print "fetch number 5 from myArr: ", myArr[5]
end

Arrays are not initialized, which means that if you read the value of an array member without previously assigning a value to it, you will get unexpected results. For example:

dim a[10]
print a[0]
rem ** this will print an undefined number **

Important: there is no runtime array bounds checking! The programmer has to make sure that the array subscript returns a number that is within the bounds of the array. Otherwise the result will be undefined.