AMSTRAD cpc 6128 User Instruction page 405

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

Advertisement

10 READ a$
20 WHILE a$<>"*"
30 PRINT a$
40 READ a$
50 WEND
60 DATA The old, desolate, battered house creaked in
the wind
70 DATA "The tall, slim, dark man coughed loudly."
80 DATA *
run
The string in line 60 contains commas, so each part will be REA D and printed
separately. The string in line 70 however, is delimited by double quotes and will be
printed as a whole, as intended.
The above example illustrates the fact that data can be spread over a number oflines.
REA D will work down the lines in number order (60, 70, 80, etc.). Another fact that
may not be obvious is that D A
T
A statements can be placed anywhere within a
program; before or after the REA D statement that picks up the information.
If a program contains more than one REA D statement, then the second REA D will
continue from the point at which the first REA D stops:
10 DATA 123, 456, 789, 321, 654, 2343
20 FOR i=1 to 5
30 READ num
40 total=total+num
50 NEXT
60 READ total2
70 IF total=total2 THEN PRINT "the data is ok"
ELSE PRINT "there is an error in the data"
run
Try editing line 1 0 so that one of the first 5 numbers is wrong, then run the program
again. This technique of adding an extra value to the end of D A
T
A statements which
is the sum of all the other values, is a good method of detecting errors in D A T A,
especially ifthere are a large number of D A
T
A lines - this is known as a 'checksum'.
If a program requires mixed data (strings and numbers), it is permissible to combine
string and numeric items in REA D and D A T A statements, as long as the items are
read correctly. For instance, if the D A
T
A contained sequences of two numbers
followed by a string - then it would only make sense to use aRE A D that was followed
by two numeric variables, then a string variable:
Chapter 9 Page 32
At your leisure ....

Advertisement

Table of Contents
loading

Table of Contents

Save PDF