Chawter
51
Basic
ConceDts
<=
or
=<
Less Than
or
Equal To. The first oper-
and is less than (precedes)
or
is equal
to
the second operand.
>=
or
=>
Greater Than or Equal To. The first
operand is greater than (follows) or is
equal
to
the second operand.
Relational operators are usually used within an IFiTHEN state-
ment.
For
example:
IF
CI
=
1
THEN PRINT "CORRECT"
BASIC looks
at
the value in variable A. If the value is equal to
1,
BASIC prints the word
CORRECT.
If arithmetic and relational operators are combined in the same
expression, BASIC evaluates the arithmetic operations first. For
example
:
IF
X*Y/2
<=
15
PRINT
"4VERAGE
SCORE"
BASIC performs the arithmetic operation
X*Y/2
and then com-
pares the result with 15.
When relational operators are used with strings,
BASIC
compares the strings character by character. When it finds
2
characters that do not match, it checks
to
see which character
has the lower value
ASCII code. The character with the lower
ASCII code comes before the word with the higher ASCII value
in an alphabetical listing, just
as
one word comes before another
in a dictionary.
Consider these examples:
"fl"
<
llgll
BASIC compares the ASCII value
of
the
2
strings. The ASCII
value for
A
is 65, and the ASCII value for B is 66. Since 65 is
less than 66, BASIC returns a
-1.
BASIC displays the result if
you type PRINT and the expression. For example, PRINT
"A">"B".
"CODE"
>
"C
00
L"
This is false. The
first
2
characters
of
the strings match. How-
ever, the third character does not. BASIC then compares the AS-
CII codes. The ASCII code
for
D
is 68 and the code for
0
is
79.
Since
79
is not less than 68, BASIC returns a
0.
"TRAIL"
<
"TRA
I
LER"
53