Chapter
10
I
BASIC
Ke.ywords
IF
X
>
0 AND
Y
<>
0 THEN
Y
=
X
+
180
assigns the value
X
+
180
to
Y
if
both exm-essions are true.
Otherwise, BASIC executes the next program- line, skipping the
THEN clause.
IF
A$
=
"YES" THEN 210 ELSE
IF
A$
=
"NO"
THEN
branches
to
Line 210 if A$ is YES. If not, BASIC skips
to
the
first ELSE, which introduces a new test.
If A$ is
NO,
then
BASIC branches
to
Line 400. If A$ is any value besides NO
or
YES, BASIC branches
to
Line 370.
400 ELSE 370
Sample
Program
IFiTHENiELSE statements may be nested. However, you must
take care
to
match up the
IFs
and ELSEs. (If the statement does
not contain the same number
of
ELSEs and IFs, each ELSE is
matched with the closest unmatched IF.)
1040 INPUT "ENTER TWO NUMBERS";
A,
B
1050
IF
A
<=
B
THEN
IF
A
<
B
THEN PRINT
A;
ELSE
PRINT
"
NEITHER"; ELSE PRINT
E;
1060 PRINT
"
IS
SMALLER THAN THE OTHER"
This program prints the relationship between the 2 numbers
entered.
176