OPERATORS
The arithmetic operators include the following signs:
+ addition
- subtraction
* multiplication
/ division
^ raising to a power (exponentation); ^ = up arrow
On a line containing more tha one operator, there is a set order in
which operations always occur. If several operators are used together,
the computer assigns priorities as follows: First, exponentiation, then
multiplication and division, and last, addition and subtraction. If two
operations have the same priority, then calculations are performed in
order from left to right. If you want these operations to occur in a
different order, BASIC allows you to give a calculation a higher
priority by placing parentheses around it. Operations enclosed in
parentheses will be calculated before any other operation. You have to
make sure that your equations have the same number of left parentheses
as right parentheses, or you will get a SYNTAX ERROR message when your
program is run.
There are also operators for equalities and inequalities, called
relational operators. Arithmetic operators always take priority over
relational operators.
= equal to
< less than
> greater than
<= less than or equal to
=< less than or equal to
>= greater than or equal to
=> greater than or equal to
<> not equal to
>< not equal to
Finally there are thee logical operators, with lower priority than both
arithmetic and relational operators:
AND
OR
NOT
These are used most often to join multiple formulas in IF...THEN
statements. When they are used with arithmetic operators, they are
evaluated last (i.e., after + and -).
Examples:
IF A=B AND C=D THEN 100
Requires both A=B & C=D to be true.
IF A=B OR C=D THEN 100
Allows either A=B or C=D to be true.
A=5:B=4:PRINT A=B
Displays a value of 0.
A=5:B=4:PRINT A>B
Displays a value of -1.
PRINT 123 AND 15:PRINT 5 OR 7
Displays 11 and 7.