OR

BASin

OR

Logical Operator/Function

OR acts as a logical operator to test the truth of a combination of conditions. If one or more of the conditions are true, then the overall combination is true. OR also acts as a function to perform binary operations on two numeric values.

How to use OR

As a logical operator, OR links two conditions in a statement where the truth is to be tested, for example

70 IF INKEY$="N" OR INKEY$="n" THEN STOP

If any of the conditions is true, then the overall combination is true. In the line above, one of the conditions (INKEY$="N" and INKEY$="n") becomes true as soon as the N key is pressed, regardless of whether CAPS SHIFT or CAPS LOCK is operating or not. The whole combination is then true and the program stops.

OR as a function

The BASIC assigns a numeric value of 1 to a true condition and 0 to a false condition. It recognises any non-zero value as true and 0 as false. OR may therefore be preceded or followed by a numeric value, for example

40 LET x=y OR z

The variable x is then assigned a value of 1 if z is non-zero or a true condition, or a value of y if z is 0 or a false condition.

This is useful in arithmetic. In the following example, the fare is halved if the age is less than 14.

60 PRINT fare*(0.5 OR age>13)

If the age is less than 14, the condition age>13 is false, so the fare is multiplied by 0.5. If age>13 is true, then the fare is multiplied by 1.

Note that the BASIC does not evaluate combinations of numeric values in accordance with standard truth tables.

Format

  • cond OR cond
  • num-expr OR num-expr

See also

Chapter 13.