EasyManua.ls Logo

Radio Shack TRS-80 Model 4 - Page 171

Radio Shack TRS-80 Model 4
418 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
String
Relations
The relational operators for string expressions are the same
as
above, although their meanings are slightly different. Instead of
comparing numerical magnitudes, the operators compare their ASCII
sequence. This allows
you
to sort string data:
< Precedes
> Follows
> < or < > Does not have the same precedence
< = Precedes or has the same precedence
> = Follows or has the same precedence
BASIC compares the string expressions
on
a character-by-character
basis. When it finds a non-matching character, it checks to see which
character has the lower ASCII code. The character with the lower
ASCII code is the smaller (precedent) of the two strings.
NOTE: Appendix C contains a listing of ASCII codes for each
character.
Examples of true relational expressions:
"A" < "B"
The ASCII code for A is decimal 65; for
Bit's
66.
"CODE" < "COOL"
The ASCII code for
a
is
79; for D it's 68.
If while making the comparison, BASIC reaches the end of one string
before finding non-matching characters, the shorter string is the
precedent. For example:
"TRAIL"
< "TRAILER"
Leading and trailing blanks are significant. For example:
"A"
< "A"
ASCII for the space character
is
32; for
A,
it's
65.
"Z-80" < "Z-80A"
The string
on
the left
is
four characters long; the string
on
the right is
five.
How to
Use
Relational
Expressions
Normally, relational expressions are used as the test
in
an
IFITHEN
statement. For example:
IF
A = 1
THEN
PRINT
"CORRECT"
BASIC tests to see if A
is
equal to
1.
If it is, BASIC prints the
message.
2-43

Other manuals for Radio Shack TRS-80 Model 4

Related product manuals