Atari
BASIC
Reference Guide 127
The expression
(EX)
that
follows
IF
can be logical
or
algebraic.
Any
algebraic expression that does
not
equal
zero
is
considered
true. The logical operators
(AND,
NOT
and OR) can be used in
the
IF
expression.
10
X =
15
20
Y =
30
EXAMPLE
30
IF
X>10
AND
Y>20
THEN
50
40
PRINT
"CONDITIONS
NOT
MET":END
50
PRINT
"CONDITIONS
HAVE
BEEN
MET"
RUN
CONDITIONS
HAVE
BEEN
MET
The previous
example shows
two
logical expressions and a
logical
operator
in the
IF
/ THEN statement (line
30).
The
AND
will
only
be
true
when
both
conditions
have been met. Since X =
15
(line
10)
and Y =
30
(line 20),
both
of
the
conditions
of
line
30
are
true.
As
a result, the
program
branches
to
line
50.
At
line
50,
the
message
CONDITIONS
HAVE
BEEN
MET
is
printed.
An
END statement
is
used in
line
40
to
prevent
both
messages
from
being
printed
when
the
IF
statement
is
false.
An IF/THEN statement can also be
followed
by statements
instead
of
a
line
number.
10 Y = 5
20
X =
10
EXAMPLE
30
IF
X<100
THEN PRINT X:PRINT Y
RUN
10
5
The previous example shows that statements can
follow
a THEN
statement, separated
by
colons.
If
the
condition
is
true,
the
statements are executed.
If
the
condition
is
false,
the
program
will
continue
at
the next
line
, and the statements after
the
THEN
statement are
ignored
.
Si
nce X =
10
(line 20), the
condition
at
line