EasyManua.ls Logo

Commodore Plus 4 - Conditional statements

Commodore Plus 4
234 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
CONDITIONAL
OR
DECISION
MAKING
STATEMENTS
Conditional
statements
are
used
to
make
decisions.
One
of
the
most
powerful
abilities
of
a
computer
is
to
make
decisions
based
on
what
is
going
on.
One
of
the conditional
statements
available
on
Ihe Plus-4
is
known
as
IF'THEN
statements,
Statement
Name:
IF/THEN
Format:
IF
condition
THEN
do
this
(only
if
the
condition
is
true)
Basically,
the
IF'THEN
statement
works
like
this.
IF (this
statement
is
true)
THEN
(do
this
statement)
Actually,
you
have
always
known
how
conditional
statements
work
How
many
times
have
you
heard
this
famous
line9
IF
you
eat
all
your
vegetables
THEN
you
can have
dessert
That
may
seem
a
bit
trivial,
but
that
is
the
gist
of
the
IF;THEN
statement.
If
the
condition
in
the
IF
statement
is
true,
everything
after
the
THEN
is
executed.
EXAMPLE.
10
INPUT'WHAT'S
THE
TENTH
LETTER
OF
THE
ALPHABET";
AS"
20
IF
AS^-J11
THEN
PRINT
"RIGHT":
GOTO
100
30
INPUT
"IS
THIS
AN
A";X$
40IFXS
=
"A"THEN60
50
PRINT
"WRONG,
TRY
AGAIN":
GOTO
30
60
PRINT"TYPE
AB"
70
GETKEYA$:IFA$
=
"B"THEN
PRINT
"RIGHT"
100
PRINT
"THAT'S
ENOUGH
OF
THIS,
ANYWAY"
In line
40,
we
just
say
THEN
60.
This
actually
means
THEN
GOTO
60.
j
but
since
the
THEN
GOTO
combination
is
used
so
often,
BASIC
allows
you
to
leave
off
the
GOTO.
An
optional
step
for
the
IF'THEN
statement
is
the
ELSE
clause,
that
directs
your
computer
to
a
specific
action
if
the
original
IF
condition
was
not
met-
An
example
showing
the
ELSE
clause
would
be:
IF
B
>
5
THEN
40
ELSE
GOTO
10.
The
BASIC
Ency-
-
clopedia
explains
the
IF/THEN/ELSE
statement
more
fully.
_
7&-

Other manuals for Commodore Plus 4

Related product manuals