Description
Arrays are
Variables which contain more than one value. The
value decided upon is chosen using an index which is an integer value between 0
and the number of elements in the array. In
ARMbasic , any
array must be declared before it's first use using the
DIM command.
The
best way to conceptualize an array is look at it like a spreadsheet. For
example, if you had an array called myArray which contained elements (0 to 10),
and was filled with random numbers, you could look at it like this:
Index Data
0 4
1 5
2 2
3 6
4 5
5 9
6 1
7 0
8 4
9 5
10 7
Keep in mind that the numbers in the Data column are
completely arbitrary in our example. When you create an array in
ARMbasic using the DIM command, the elements are all set to 0.
If you were to look at myArray(1), you'd find it's equal to 5.
If you were tolook at myArray(5),you'd find it equal to 9. In
ARMbasic , you can for the most part treat arrays with indexes
the same as you would all Variables.
Arrays can hold BYTE, INTEGER or SINGLE values.
Example
DIM Numbers( 10)
DIM OtherNumbers( 10)
Numbers(1) = 1
Numbers(2) = 2
OtherNumbers(1) = 3
OtherNumbers(2) = 4
GOSUB PrintArray
FOR a =
1 TO 10
PRINT Numbers(a)
NEXT
a
PRINT OtherNumbers(1)
PRINT
OtherNumbers(2)
PRINT OtherNumbers(3)
PRINT OtherNumbers(4)
PRINT
OtherNumbers(5)
PRINT OtherNumbers(6)
PRINT OtherNumbers(7)
PRINT
OtherNumbers(8)
PRINT OtherNumbers(9)
PRINT OtherNumbers(10)
PrintArray:
FOR i = 1 TO
10
PRINT
otherNumbers(i)
NEXT i
RETURN
See also