EasyManua.ls Logo

Commodore Plus 4 - Control Statements and Loops; CHAPTER 7 Using Graphics and Color

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...
CONTROL
STATEMENTS
AND
LOOPS
n
~
It
would be
pretty
boring
if
your
computer
could
only
execute
program
lines
in
order.
The
computer
could
only
star!
at
the
beginning
and
go
through
each
step
in
order
until
the
end
of
the
program.
This
would
lead
lo
very long
programs;
if
you
wanted
to
do
the
same
thing
twice
(like
PRINT
"HELLO"),
you
would
have
lo
duplicate
the
program
lines.
With
a small
example
like
PRINTing
HELLO,
this
doesn't
make
a
lot
of
difference,
but
it
could
become
difficult
in
larger
programs.
This
is
why
computers
have
control
statements.
Control
statements
tell
the
com
puter
to
ignore
the
normal
order
of
the
program
lines,
and
go
to
another
line
regardless
of
the
sequence.
The
Plus/4
has
several
varieties
of
control
statements,
unconditional
(like
GOTO)
which
always
transfer
control;
counting
statements
(like
FOR/NEXT}
which
transfer
control
a
specified
number
of
times;
and,
for
you
structured
programming
fans
out
there,
DO/LOOP.
Statement
Name:
GOTO
Format.GOTO
line
#
GOTO
tells
your
computer
to
immediately
go
from
the
current
line
in
your
program
to
the
line
number
specified
in
the
GOTO
statement.
For
example,
if
line
20
reads
GOTO
40.
your
Plus/4
would
jump
to
line
40,
skipping
any
statements
between
20
and
40.
Example
using
GOTO
statement
in
a
program.
TYPE:
10
PRINT
"A
PENNY
SAVED
IS
BETTER
THAN
NOTHING"
20
GOTO
10
The
computer
responds
by
printing
the
message
in
line
10
again
and
again,
until
you
press
the
STOP
key,
like
this:
A
PENNY
SAVED
IS
BETTER
THAN
NOTHING
A
PENNY
SAVED
IS
BETTER
THAN
NOTHING
A
PENNY
SAVED
IS
BETTER
THAN
NOTHING
~
BREAK
IN
10
READY.
If
you
press
the
STOP
key
This
print
statement
will
continue
'forever1.
Every
time
your
Plus/4
gets
to
the
GOTO
in
line
20
it
goes back
to
line
10.
This
is
called
an
INFINITE
76

Other manuals for Commodore Plus 4

Related product manuals