Smart BASIC Programming. Lesson 5
Posted: Fri Nov 14, 2014 5:31 am
Lesson 5 - Arrays
Besides usual variables, in smart BASIC you can also use arrays. Array is a variable which can hold multiple values. Each value is addressed by using index. For example, command
creates array M, which contains 100 values. You can access array values by indicating value index in brackets. Indices start with 0, so this array M contains values with indices from 0 to 99.
Arrays can be one-, two- or three-dimensional:
Using command OPTION BASE 1 it is possible to set that indices start with 1 instead of 0:
EXERCISE 6
Draw maze on the screen.
Besides usual variables, in smart BASIC you can also use arrays. Array is a variable which can hold multiple values. Each value is addressed by using index. For example, command
Code: Select all
DIM M (100)
Code: Select all
N = 12 'number of array values
DIM X (N) 'create array
'fill array
FOR K = 0 TO N - 1
X (K) = K ^ 2
NEXT K
'read array
FOR K = 0 TO N - 1
PRINT K; X (K)
NEXT K
Code: Select all
DIM X (30) 'one-dimensional array
DIM Y (20,30) 'two-dimensional array
DIM Z (50,50,50) 'three-dimensional array
Code: Select all
OPTION BASE 1
DIM X (12) 'create array
'fill array
FOR K = 1 TO 12
X (K) = K ^ 2
NEXT K
'read array
FOR K = 1 TO 12
PRINT K; X (K)
NEXT K
Draw maze on the screen.