Using Data - AMSTRAD cpc 6128 User Instruction

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

Advertisement

Usmgdata ....
In a program that always requires the same set of information to be input at the start,
it would make more sense if there were some way of entering all the values without
having to ask the user to type them in every time. This facility is provided by the
REA D and D A T A commands. The word REA D is very similar to I N PUT in that it can
be used to assign values to variables. It differs, however, in the fact that values are
read from D A T A statements, rather than prompting for input from the keyboard. The
following two examples show this:
1111 INPUT "enter 3 numbers separated by commas";a,b,c
20 PRINT "the numbers are";a;"and";b;"and";c
run
10
READ a,b,c
20 PRINT "the numbers are";a;"and";b;"and";c
30 DATA 12,14,21
run
In the same way that different items in an I N PUT statement are separated by
commas, so it is with items in a D A T A statement.
In addition to numeric values, constant strings may also be held in D A T A statements:
10
DIM a$(8)
20 FORi=0 TO 8
30 READ a$(i)
40 NEXT
50 FOR ;=0 TO 8
60 PRINT a$(i);" ";
70 NEXT
80 DATA The,quick,brown,fox,jumps,over,the,lazy,dog
run
You may notice that although the D A T A contains strings, the strings are not
enclosed by double quotes "". The use of double quotes in D A T A statements to
delimit (separate) strings is optional, just as they are when typing a string in answer
to an IN PUT statement. One occasion that double quotes are useful however, is when
the string D A T A itself contains commas. If strings are not delimited by double quotes
under these circumstances, the REA D statement will use the commas to delimit the
strings in the D A T A statement.
At
you
leisure ....
Chapter 9 Page 31

Advertisement

Table of Contents
loading

Table of Contents