qb45advr.hlp (
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Hierarchy of Operations
◄Expressions and Operators► ◄Hierarchy► ◄Contents► ◄Index►
──────────────────────────────────────────────────────────────────────────────
Hierarchy of Operations
When several BASIC operators occur in the same statement, they are executed
in the following order:
1. Arithmetic operations
a. Exponentiation (^)
b. Negation (-)
c. Multiplication and division (*, /)
d. Integer division ()
e. Modulo arithmetic (MOD)
f. Addition and subtraction (+, -)
2. Relational operations (=, >, <, <>, <=, >=)
3. Logical operations
a. NOT
b. AND
c. OR
d. XOR
e. EQV
f. IMP
An exception to the order of operations listed above occurs when an
expression has adjacent exponentiation and negation operators. In this
case, the negation is done first. For example, the following statement
prints the value .0625, not -16:
PRINT 4 ^ - 2
If the operations are different and are of the same level, the leftmost one
is executed first and the rightmost last, as explained below.
A = 3 + 6 / 12 * 3 - 2 'A = 2.5
The order of operations in the preceding example is as follows:
1. 6 / 12 (= 0.5)
2. 0.5 * 3 (= 1.5)
3. 3 + 1.5 (= 4.5)
4. 4.5 - 2 (= 2.5)