Chapter
3:
Programming the
VIC
20
Computer 73
Relational operators
can
be used
to
compare strings.
For
comparison
purposes, the letters
ofthe
alphabet have the
order
A <
B,
B < C, C <
D,
and
so on. Strings are compared one character
at
a time, starting with the
leftmost character.
"A"<"B"
"X" = "XX"
CS
= AS+BS
results in true
(-I)
results in false
(0)
result
will
depend
on the string values assigned
to the three string variables
CS,
BS,
and
AS
When operating
on
strings, VIC BASIC generates a value
of
-1
for a
"true" result,
and
a value
of
0 for a "false" result.
("JONES">"DOEj
+37
is
the same as
-1+37
("AAA"<
"AA'') *
(Z9-("OTTER">
"AB''»
is
the same as 0 *
(Z9-(-I»
BOOIIAN
OPERATORS
Boolean operators give programs the ability
to
make logical decisions.
There are three Boolean operators
in
VIC BASIC: AND,
OR,
and
NOT.
A simple supermarket shopping analogy
can
serve
to
illustrate Boolean
logic. Suppo&e you are shopping for breakfast cereals with two children.
The
AND
Boolean
operator
says
that
a cereal is selected only if child A
and
child B select the cereal.
The
OR
Boolean
operator
says
that
a cereal will be selected if either
child A
or
child B selects the cereal.
The
NOT
operator
generates a logical opposite.
If
child B insists
on
disagreeing with child A, then child B's decision is always
not
child A's
decision.
Table 3-3 summarizes the way in which Boolean operators handle
numbers. This table is referred
to
as a
truth
table.
Boolean operators primarily control
program
logic. Here are some
examples.
IF
A =
100
AND B =100 GOTO
10
If
both A and B are equal to
100,
branch to line
10
IF
X < Y AND
B>
=
44
THEN F = 0
If
X
is
less
than Y and B
is
greater than or equal to
44,
then set F equal to 0
IF
A =
100
OR B =
100
GOTO
20
If
either A or B has a value of
100,
branch to line
20