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 &
NOT
X, X and Y will each usually take the value 0 or 1, for false
or true. Work out the ten different combinations & check that they do what you expect
AND
,
OR
&
NOT
to
do.
4. Try this program:
10
INPUT
A
20
INPUT
B
30
PRINT
(A
AND
A
>=
B)+(B
AND
A<B)
40
GOTO
10
Each time it prints the larger of the two numbers A & B - why?
Convince yourself that you can think of
X AND Y
as meaning
'X if Y (else the result is 0)'
& of
X
OR
Y
as meaning
'X unless Y (in which case the result is 1)'
An expression using
AND
&
OR
like this is called a conditional expression. An example using
OR
could
be
LET
RETAIL PRICE=PRICE LESS VAT*(1.15
OR
V$="ZERO RATED")
Notice how
AND
tends to go with addition (because its default value is 0), &
OR
tends to go with
multiplication (because its default value is 1).
5. You can also make string valued conditional expressions, but only using
AND
.
so it means 'X$ if Y (else the empty string)'.
Try this program, which inputs two strings & puts them in alphabetical order.
10
INPUT
A$
20
INPUT
B$
X
AND
Y has the
value
{ X if Y is non-zero (counting as
true)
{ 0 if Y is zero (counting as
false)
X
OR
Y has the
value
{ 1 if Y is non-zero
{ X if Y is zero
NOT
X has the
value
{ 0 if X is non-zero
{ 1 if X is zero
X$
AND
Y$ has the value
{ X$ if Y is non-zero
{ if Y is zero