TRS-80 MODEL III
Hierarchy of Operators
When your
expressions have multiple
operators, BASIC performs the operations
according
to a
well-defined hierarchy, so
that results are always predictable.
Parentheses
When a complex
expression includes parentheses, BASIC always evaluates
the
expressions inside the
parentheses before evaluating the
rest
of the
expression.
For example, the expression:
8-
(3-2)
is evaluated like this:
3-2=1
8-1=7
With nested parentheses, BASIC starts
evaluating the innermost level first and
works outward. For example:
4*(2-(3-4))
is evaluated like this:
3-4=
-1
2-(-1)
=
3
4*3=
12
Order of Operations
When evaluating
a
sequence of operations on the same level of parenthesis,
BASIC uses
a
hierarchy
to
determine what operation to do first.
The two
listings
below
show the hierarchy BASIC
uses.
Operators are shown
in
decreasing order
of
precedence. Operators listed in the same entry in
the table
have
the same
precedence and are executed
as
encountered
from left to right:
Numerical operations:
[
+
,
-
(Unary sign
or (Exponentiation)
operands
[not
addition and subtraction])
*
/
+
,
-
<
(Addition and subtraction)
,
>,
=,
<
=
,
>
=
,
<>
NOT
AND
OR
120