Beginner's Programming Tutorial in QBasic

(Kiana) #1

Arrays


An array is a list of variables of the same type. Arrays are useful for organizing multiple variables.
To create an array, use the DIM (dimension) command.
The following example does not use arrays:
a = 2b = 4
c = 6
d = 8e = 10
PRINT a, b, c, d, e
Output:
2 4 6 8 10
This uses an array called vars, which contains 5 variables:
DIM vars(5)
' Each of these are separate variables:vars(1) = 2
vars(2) = 4
vars(3) = 6vars(4) = 8
vars(5) = 10
PRINT vars(1), vars(2), vars(3), vars(4), vars(5)
Output:
2 4 6 8 10


( NOTE: How an array of variables is stored in memory Memory addresses are not necessarily as specified)
Free download pdf