Contents / Part 3 / Previous chapter / Next chapter / Index
An operator is something like +, /, < etc, which affects one or more items - for example comparing, them, or adding them.
Mathematical operators are familiar. Most act on two numbers- for example
7 DIV 4 integer division
7 MOD 4 integer remainder
3 ^ 4 raise to a power
These operators are referred to as binary operators since they require two operands (i.e., two things to operate on)
This shows one of the key 'unary' operators that we are used to - the - just acts on the 5 to make it a negative number.
This version of BASIC: has a large number of operators and it is very important that the user is aware of their order of precedence. You will remember that in mathematics multiplication must be completed before addition - the same applies to other operators - there is a strict hierarchy and you must be aware of it if the computer is to do what you expect.
The overall order of precedence (or operators is as follows.
All operators in each group have equal priority and will be dealt with on a left to right basis - in other words in order in each line.
Some of the operators should be familiar by now; others may need explanation.
NOT is most often used to reverse the result of a test. e.g. IF NOT(X=5)THEN... Clearly this example could be written IF X <> 5 THEN but the operator NOT is often essential when using functions e.g. IF NOT FNVALID THEN...
Functions include all the predefined functions such as SQR, SIN, ASC etc and user defined functions like FNVALID.
Brackets can be used to ensure that everything within the brackets is evaluated before any other calculations take place. Indirection operators are described in section 39 on page 411.
Raise to the power e.g.
These contain all the usual arithmetic operators. Nothing unexpected here.
This contains the relational operators which mean 'greater than', 'less than', etc. They are used in expressions such as
IF X>10 THEN . . .
Logical AND is used to ensure that two or more conditions hold true before some action is taken e.g.
IF X>10 AND Y=6 THEN . . .
For further details see the entry on page 205
Logical OR is also used with multiple conditions e.g.
IF X>10 OR Y=6 THEN
The action is taken if one or more of the conditions is true. EOR is normally only used as a bitwise operator and the user is referred to page 250 for details.