AMSTRAD cpc 6128 User Instruction page 406

Integrated computer/disc system
Hide thumbs Also See for cpc 6128:
Table of Contents

Advertisement

10 DIM a(5),b(5),s$(5)
20 FOR ;=1 TO 5
30 READ a(i),b(i),s$(i)
40 NEXT
50 DATA 1,7,fred,3,9,j;m,2,2,er;c,4,6,peter,9,1,alfonzo
60 FOR ;=1 TO 5
70 PRINT s$(;),":";a(;)*b(;)
80 NEXT
Alternatively, you may wish to separate the different types of data:
10 DIM a(5),b(5),s$(5)
20 FOR ;=1 TO 5
30 READ a(;),b(;)
40 NEXT
50 FOR ;=1 TO 5
60 READ 's$(;)
70 NEXT
80 DATA 1,7,3,9,2,2,4,6,9,1
90 DATA fred,j;m,er;c,peter,alfonzo
100 FOR ;=1 TO 5
110 PRINT s$(;),":";a(i)*b(;)
120 NEXT
Ifthe FOR loop in line 20 is now changed to:
20 FOR ;=1 TO 4
.... then the first two attempts to read strings in line 60 will produce '9' then' 1 '. These
values are of course valid strings, but the result is not exactly what was planned! One
method by which the program could be forced to work properly, would be to include
the following commands:
15 RESTORE 80
45 RESTORE 90
The RES TOR E statement will move the D A T A-reading 'pointer' to the line specified,
and can therefore be used in a conditional statement to pick a certain block of data to
be read depending upon some criterion. For instance, in a multi-level game which has
a number of different screens, the D A
T
A for each screen may be picked according to
some variable - for example' L eve L'. The following is just an example section of such
a program:
At your leisure ....
Chapter 9 Page 33

Advertisement

Table of Contents
loading

Table of Contents

Save PDF