Equational And/Or

Author(s): Paul Ezra
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n1 (Volume 3, Issue 1)
Date: January 1982
Pages: 13

Many users are confused about the logical use of AND and OR in the 8K ROM. Here is a touchstone (demonstration) program illustrating various uses of AND and OR.

  10 LET A=1
20 LET B=2
30 LET C=3
40 LET D=4
50 LET E=5
60 IF E=5 AND D=4 AND C=3 THEN PRINT "THE PEACH ";
70 IF E=4 OR E=5 THEN PRINT "BLOSSOMS ";
80 IF (D=5 AND E=4) OR (D=4 AND E=5) THEN PRINT "SMELL ";
90 IF (D=4 OR D=5) AND (A=2 OR A=1) THEN PRINT "GOOD ";
99 IF B=1 OR B=3 OR B=2 THEN PRINT "TODAY."

Does the whole sentence print? Run the program to find out.

Note that here we are only describing the use of AND/OR separating equations (like X=Y AND Z=A), not the use of AND/OR without equations (like X AND Y). We will tackle the latter use at another time to better separate the two broad uses in your mind.

We recently used this line in a program and it worked:

 764 IF M$(C,1)=M$(C,5) AND M$(C,2)=M$(C,6) AND M$(C,1)=M$(H,1) AND M$(C,5)=M$(H,5) AND M$(C,2)=M$(H,2) AND M$(C,6)=M$(H,6) AND ((M$(C,3)<>M$(H,3) AND M$(C,7)<>M$(H,7)) OR (M$(C,4)<>M$(H,4) AND M$(C,8)<>M$(H,8))) THEN LET E(1)=E(1)+1

You can use the touchstone program to guide you in contructing such complex lines.

Note that if A is true and B is false, A AND B is false, but A OR B is true. In an IF-THEN statement, true results tell the computer to execute the command after THEN. False results cause the computer to skip the command after THEN.–AZ

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.