<!-- PDF page 72 -->

**NOT** (*the first*) **AND NOT** (*the second*)

Using this, you can work **NOT**s through parentheses until eventually they are all applied to relations, and then you can get rid of them. Logically speaking, **NOT** is unnecessary, although you might still find that using it makes a program clearer.

The following section is quite complicated, and can be skipped by the fainthearted!

Try:

```
PRINT 1=2,1<>2
```

which you might expect to give a syntax error. In fact, as far as the computer is concerned, there is no such thing as a logical value: instead it uses ordinary numbers, subject to a few rules.

1. =, <, >, <=, >= and <> all give numeric results: **1** for *true*, and **0** for *false*. Thus the **PRINT** command above printed **0** for **1=2**, which is *false*, and **1** for **1<>2**, which is *true*.
2. In: **IF** *condition* **THEN** ... the condition can be actually any numeric expression. If its value is **0**, then it counts as *false*, and any other value (including the value of **1** that a *true* relation gives) counts as *true*. Thus the **IF** statement means exactly the same as:\
   **IF** *condition* <>**0 THEN . . .**
3. **AND, OR** and **NOT** are also number-valued operations.

   <table>
   <tbody>
   <tr><td rowspan="2">x <strong>AND</strong> <em>y</em> has the value</td><td rowspan="2">{</td><td><strong>x</strong> if <em>y</em> is <em>true</em> (non-zero)</td></tr>
   <tr><td><strong>0</strong> (<em>false</em>), if <em>y</em> is <em>false</em> (zero)</td></tr>
   </tbody>
   </table>

   <table>
   <tbody>
   <tr><td rowspan="2"><em>x</em> <strong>OR</strong> <em>y</em> has the value</td><td rowspan="2">{</td><td><strong>1</strong> (true) if <em>y</em> is <em>true</em> (non-zero)</td></tr>
   <tr><td><strong>x</strong>, if <em>y</em> is <em>false</em> (zero)</td></tr>
   </tbody>
   </table>

   <table>
   <tbody>
   <tr><td rowspan="2"><strong>NOT</strong> <em>x</em> has the value</td><td rowspan="2">{</td><td><strong>0</strong> (<em>false</em>), if <em>x</em> is <em>true</em> (non-zero)</td></tr>
   <tr><td><strong>1</strong> (<em>true</em>), if <em>x</em> is <em>false</em> (zero)</td></tr>
   </tbody>
   </table>

(Notice that *true* means *non-zero* when we're checking a given value, but it means **1** when we're producing a new one.)

Read through the chapter again in the light of this revelation, making sure that it all works.

In the expressions **x AND y**, **x OR y** and **NOT x**, *x* and y will usually take the values **0** and **1** for *false* and *true*. Work out the ten different combinations (four for **AND**, four for **OR** and two for **NOT**) and check that they do what the chapter leads you to expect them to do.

Try this program:

```
10 INPUT a
20 INPUT b
30 PRINT (a AND a>=b)+(b AND
   a<b)
40 GO TO 10
```

Each time it prints the larger of the two numbers **a** and **b**.\
Convince yourself that you can think of:

**x AND y** as meaning: *x* if *y* (else the result is **0**)

and of:

**x OR y** as meaning: *x* **unless** *y* (in which case the result is **1**)

