Chapter
3:
Programming the
VIC
20
Computer 91
Ie}
A%
= 1
(~:
A"-BX-2
40~ON
A~
OOTO
'.13,7'0,150
30
69
79
A%=
299
99
1913
119
129
1313
149
159
169
The statement
on
line
40
is
a computed GOTO. When this statement
executes, the program will branch to statement
10
if variable
A%
=
1,
to
statement
70
if variable
A%
=
2,
or
to statement
150
if
A%
=
3.
If
A%
has
any value other
than
1,2,
or
3, the program will not branch. Notice
that
variable
A%
is assigned a value in statement 30. The value assigned to
A%
depends
on
the current value
of
variable
B%.
The illustration does not show
how variable
B%
is
computed,
but
as long as
B%
has a value of 3,4,
or
5, the
statement on line
40
will cause a branch.
To test the computed GOTO statement, key in the following program:
113
Br--4
213
PRINT
BX
39
A"-B"-2
49
ON
A"OOTO
19,79,1513
79
PRINT
Br-
89
BX-S
99
OOTO
39
139
PRINT
B~
1613
B"-3
179
OOTO
29
Now execute this program by typing RUN on any blank line. Do not
type RUN
ona
line
that
is
already displaying something.
If
you do, you will
get a syntax error and the program will not be executed.
Can you account for the sequence in which digits are displayed? Try
rewriting the program so
that
each number
is
displayed once, in the
sequence 345345345 ...