Chapter 3 Programming the
VIC
20
Computer 111
will execute endlessly since the GOTO statement selects itself for the execu-
tion.
We
could replace this statement with a
STOP
statement. When a
STOP statement
is
executed, the following message will appear:
BREAK
IN
XXXX
READY
Then execution stops. XXXX
is
the line number
of
the
STOP
statement.
If
you have more
than
one
STOP
statement in your program, use the line
number to identify which one was executed.
FUNCTIONS
Another element of VIC BASIC
is
the/unction,
which in some ways
looks like a variable,
but
in other ways acts more like a BASIC statement.
Perhaps the simplest way of illustrating a function
is
to look at
an
example in an assignment statement.
10
RCIISQR(B)
The variable A has been set equal to the square root of the variable
B.
SQR
specifies the square root function. Here
is
a string function.
In this example the string variable
C$
is
set equal to the first two characters
of
string variable D$.
Functions can substitute for variables
or
constants anywhere in a
BASIC statement, except to the left
of
an equal sign. In other words, you can
say that A
= SQR(B), but you cannot say
that
SQR(A) =
B.
We
have already used four functions. SPC, TAB, and POS are system
functions used with the
PRINT
statement to format displays. PEEK
is
also a
function.
The discussion which follows shows you how to use functions. A brief
incomplete summary of the VIC BASIC functions
is
presented here, but
complete descriptions
of
all functions are given in Appendixes G
and
H.
You specify a function using
an
abbreviation (such as
SQR
for square
root), followed by
arguments enclosed in parentheses. In the case of
A
= SQR(B),
SQR
requires a single argument, which in this case
is
the
variable
B.
For
C$
= LEFT$(D$,2), LEFT$ specifies the function; the two