Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF

105 70 Y(2,3)=1960 … etc. In practice it would involve a lot less typing, and make the program shorter, if all the figures were held in DATA statements. You may well need to skip this section at first and return to it when you have understood chapter 22 which deals with the keywords READ , DATA and RESTORE . If you use READ and DATA to fill the above five by three array the program could look like this:

10 DIM Y(5,3) 20 FOR COLUMN=1 TO 5 30 FOR ROW=1 TO 3 40 READ Y(COLUMN, ROW) 50 NEXT ROW 60 NEXT COLUMN 500 DATA 21,2,1964 510 DATA 12,2,1960 520 DATA 4,2,1950 530 DATA 24,10,1959 540 DATA 19,12,1962 The program above takes successive numbers from the DATA statements and inserts them into the array. Once this program has been run the array will be set up – filled with the figures – and other sections of the program (not shown above) could search the array as required. The array above is a ‘two-dimensional array’ used to store numbers. The phrase ‘two dimensional’ refers to the fact that there are five entries in one dimension and three entries in another dimension – a total of 15 entries.

A three-dimensional array could be defined with the statement DIM W(4,5,6) and a four-dimensional array with DIM T(2,2,5,3) This last array would have 2x2x5x3 (60) individual entries. Actually, array elements can be numbered from zero instead of one, so an array declared with DIM V(3) has, in fact, got four elements which are V(0) , V(1) , V(2) and V(3) . Similarly the array T(2,2,5,3) has 3x3x6x4 (216) elements and will take up over 1000 bytes of memory. Multi-dimension arrays are voracious memory eaters – only use them when needed and, if at all possible, use every element that you set up. There is no limit, other than lack of memory, on the number of dimensions in an array.