Chapter
10
I
BASIC
Keywords
IF/THE
N/E
LSE
Statement
IF
expression THEN statemnt(s)[ELSE statemnt(s)]
Tests a conditional expression and makes a decision regarding
program flow.
Expresswn
is any numeric or string expression, usually making
logical or relational comparisons.
Statement
can be
1
or
more valid BASIC statements.
If
there is
more than
1
statement, they must be separated by colons. You
can also specify a line number for BASIC
to
branch as a
statement
.
If
expression
is true, BASIC executes the THEN
statement.
If
expresswn
is
false, BASIC executes the matching ELSE
statement
or the next program line.
You can also use IFiTHEN
to
test the numeric value
of
a vari-
able.
If
the variable contains a
0,
the expression is true; other-
wise, the expression is false.
Examples
IF
X
>
127
THEN PRINT "OUT OF RANGE"
:
END
passes control
to
PRINT and, then
to
END if
X
is greater than
127.
If
X
is not greater than
127,
BASIC executes the next line
in the program, skipping the PRINT and END statements.
IF A
<
B
THEN PRINT
"A
<
E"
ELSE PRINT
"E
<=
A"
tests the first expression.
If
it is true, BASIC prints
A
<
B.
Otherwise, BASIC jumps
to
the ELSE statement and prints
B
<=
A.
175