Commodore PET User Manual page 78

Table of Contents

Advertisement

Order of Evaluation
When an expression has multiple operations. as in:
A+C*10/212
there is a built-in hierarchy for evaluating the expression. First is exponentiation
(l). followed by unary minus
(-1.
followed by multiplication and division
(*/1.
followed by addition and subtraction (+ -). Operators of the same hierarchy are
evaluated from left to right.
This natural order of operation can be overridden by the use of
parentheses. Any operation within parentheses is performed first.
Examples:
4+1.2
(4+1).2
100·4/2-1
100.(4/2-1 )
100.(4/(2-1))
results in 6
results in 10
results in 199
results in 100
results in 400
When parentheses are present. PET BASIC evaluates the innermost set first.
then the next innermost. etc. Parentheses can be nested to any level and may be
used freely to clarify the order of operations being performed in an expression.
Relational Operators
A relational operator specifies a "true" or "fa Ise" relationship between
adjacent terms. The specified comparison is made. and then the relational
expression is replaced by a value of true (-1) or false (0). Relational operators
are listed in Table 3-4 at the end of this chapter. Relational opera tors are evalu-
ated after ail arithmetic operations have been performed.
Examples:
1=5-4
14>66
15> =15
A< >B
resultsin true (-1)
resu Its in fa Ise (0)
results in true (-1)
Relational operators can be used to compare strings. For comparison pur-
poses. the letters of the alphabet have the order A
<
B. B
<
C. C
<
D. etc. Strings
are compared by comparing their stored character values. Characters are stored
using a special binary code called "ASCI!." Appendix A lists the ASCII code
assigned to every PET character.
Examples:
"A"<"B"
"X"="XX"
C$=A$+B$
results in true (-1)
results in false (0)
65

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Cbm

Table of Contents