====== 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). Floats are not allowed 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 **''DIM'' does not initialize the array**, 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 note**: 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. ===== Fast array lookup ===== If the variable and index are both byte types, the compiler can take advantage of the processor's indexed addressing mode resulting to much faster array load and store operations. For example: dim arr![255] fastindex! = 42 slowindex = 42 rem -- fast lookup item! = arr![fastindex!] rem -- slow lookup item! = arr![slowindex]