Using Arrays; Subscripted Variables - Commodore 128 System Manual

Hide thumbs Also See for 128:
Table of Contents

Advertisement

If the READ statement calls for a string variable, you can place
letters or numbers in the DATA statement. Notice however, that
since the computer is READing a string, numbers will be stored
as a string of characters, not as a value which can be
manipulated. Numbers stored as strings can be printed, but not
used in calculations. Also, you cannot place letters in a DATA
statement if the READ statement calls for a number variable.

Using Arrays

You have seen how to use READ-DATA to provide many values
for a variable. But what if you want the computer to remember all
the data in the DATA statement instead of replacing the value of
a variable with the new data? What if you want to be able to recall
the third number, or the second string of characters?
Each time you assign a new value to a variable, the computer
erases the old value in the variable's box in memory and stores
the new value in its place. You can tell the computer to reserve a
row of boxes in memory and store every value that you assign to
that variable in your program. This row of boxes is called an
array.

Subscripted Variables

If the array contains all of the values assigned to the variable X in
the READ-DATA example, it is called the X array. The first value
assigned to X in the program is named X(1), the second value is
X(2), and so on. These are called subscripted variables. The
numbers in the parentheses are called subscripts. You can use a
variable or a calculation as a subscript. The following is another
version of the averaging program, this time using subscripted
variables.
5 DIM X(5)
10 T=0
20 FOR J=1 TO 5
30 READ X(J)
40 T=T+X(J)
50 NEXT
60 A =T/5
70 ? " AVERAGE =";A
80 END
90 DATA 5,12,1,34,18
4-13

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

128d

Table of Contents