Commodore 2001-8 User Manual page 53

Table of Contents

Advertisement

Some hints
You may change the value of the counting variable during the looping sequence.
For example,
10 FOR 1=1 TO 8
20X=X+1
3OIFI=7THEN 1=8
40 NEXT
50 PRINT X
will compute the value
X=1+2+3+4+5+6+7=28
Similarly, when you exit a FOR·NEXT loop using a branch, you should assign the counting variable the
end value and then exit the loop via a NEXT statement. For instance, you should use
10 FOR 1=1 TO 10
20 IF FNA(I)=OTHEN 1=10
30 NEXT:RETURN
instead of
10 FOR 1=1 TO 10
20 IF FNA(I) =0 THEN RETURN
30 NEXT
SUBSCRIPTED VARIABLES
Array variables need not be declared with
a
DIM statement if they hav.e only one dimension and contain
less than 10 elements. The total number of elements in an array can be computed by multiplying the
(number of elements in each dimension)
+
1 by the other subscripts. Thus A(9,8) contains (9$1)*(8$1)
elements. SUbscripts start at 0 and go up to the maximum value
A(0,0)-------A(0,8)
A(9,0)
A(9,8)
Limits on the number of dimensions and size of a dimenslon are determined by size of memory available
and space available on a line following a DIM. PET BASIC restrict the total number of
array elements to 256. Each array element requires at least 5·bytes of storage.
If a single dimension array requires more than 10 elements, the DIM statement must be executed before
the first reference. Otherwise, a REDIM'ED ARRAY error will occur.
Example: List of account balances
1
$100
2
$135
3
$57.86
4
<$
9 8 7>
5
$22
6
<$ 6 3
>
7
$ 5 0
8
<$ 2 1
>
9
$ 21
Suppose we need to write a simple program which allowed you to INPUT an account number and a
transaction and keep a running total on each account. We could refer to each account balance as A1, A2,
49

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents