IBM 5110 Basic Introduction page 103

Table of Contents

Advertisement

(::'
C'
c
c
Again, when you are using large amounts of data, listing them all
separately in a READ statement is not practical. In this example, you
can take advantage of a FOR-NEXT loop to assign values:
or
0020 FOR 1=1 TO 12
0030 READ T(I)
0040 NEXT I
0050 DATA 28,31,35,49,60,64,75,81,71,59,46,37
0020 FOR 1=1 TO 12
0030 READ W(I,2)
0040 NEXT I
0050 DATA 28,31,35,49,60,64,75,81,71,59,46,37
These statements assign all the average temperature data to array T or
to the second column of array W. (For array W, since we are
assigning values only to the second column, we used a constant of 2
in the READ statement.) You can't avoid specifying 12 values in the
DATA statement, but a loop like this makes the READ statement
easier to handle.
When assigning values to array W, you could, in fact, use one READ
statement and two loops to assign
all
the data at once. It would look
like this:
0020 FOR 1=1 TO 12
0030 FOR J=1 TO
3
0040 READ W(I,J)
0050 NEXT J
0060 NEXT I
Arranged this way, the loops let you enter the data for each row of
the array in succession. Your DATA statements might look like this:
0070 DATA 1,28,3.47
0080 OAT A 2,31,2.10
0090 DATA 3,35,2.95
We've entered the data for each row of array W in a separate DATA
statement because it is easier to visualize the data that way. You
could, however, string out the data so that more than one row appears
in a DATA statement like this:
0070 DATA 1,28,3.47,2,31,2.10,3,35,2.95 ...
This way you could enter as many data items in each DATA statement
as will fit on a line. The important thing is that the data must appear
in the same order as if you were entering it row by row.
Arrays
99
(::'
C'
c
c
Again, when you are using large amounts of data, listing them all
separately in a READ statement is not practical. In this example, you
can take advantage of a FOR-NEXT loop to assign values:
or
0020 FOR 1=1 TO 12
0030 READ T(I)
0040 NEXT I
0050 DATA 28,31,35,49,60,64,75,81,71,59,46,37
0020 FOR 1=1 TO 12
0030 READ W(I,2)
0040 NEXT I
0050 DATA 28,31,35,49,60,64,75,81,71,59,46,37
These statements assign all the average temperature data to array T or
to the second column of array W. (For array W, since we are
assigning values only to the second column, we used a constant of 2
in the READ statement.) You can't avoid specifying 12 values in the
DATA statement, but a loop like this makes the READ statement
easier to handle.
When assigning values to array W, you could, in fact, use one READ
statement and two loops to assign
all
the data at once. It would look
like this:
0020 FOR 1=1 TO 12
0030 FOR J=1 TO
3
0040 READ W(I,J)
0050 NEXT J
0060 NEXT I
Arranged this way, the loops let you enter the data for each row of
the array in succession. Your DATA statements might look like this:
0070 DATA 1,28,3.47
0080 OAT A 2,31,2.10
0090 DATA 3,35,2.95
We've entered the data for each row of array W in a separate DATA
statement because it is easier to visualize the data that way. You
could, however, string out the data so that more than one row appears
in a DATA statement like this:
0070 DATA 1,28,3.47,2,31,2.10,3,35,2.95 ...
This way you could enter as many data items in each DATA statement
as will fit on a line. The important thing is that the data must appear
in the same order as if you were entering it row by row.
Arrays
99

Advertisement

Table of Contents
loading

Table of Contents