EasyManua.ls Logo

Commodore Plus 4 - Page 84

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...
LOOP
in
computerese.
While
you
might
want
to
do
this,
usually
you
want
to
repeat
only
a
certain
number
of
times,
or
until
something
hap
pens
That
is
why
the
FOR/NEXT
and
DO/LOOP
statements
are
avail
able
in
BASIC
GOTO
can
also
be
used
in
direct
mode.
GOTO
line
#
will
start
the
program
at
the
line
you
specify,
while
keeping
the
variables
the
same
(instead
of
clearing
them
as
RUN
does).
Statement
Name
FOR
NEXT
Format
FOR
variable
=
start
value
TO
end
value
some
BASIC
statements
NEXT
variable
The
FOR'NEXT
statements
let
you
create
a
loop
that
will
repeat
a
certain
number
of
times
The
program
statements
between
the
FOR
statemenl
and
the
matching
NEXT
statement
are
repeated
in
the
loop
The
variable
in
the
FOR
statement
acts
as a counter
It
is
initially
set
at
the
start
value
you
supply.
Then,
the
program
lines after
the
FOR
are
executed,
until
the
computer
gets
to
the
matching
NEXT
statement.
The
NEXT
tells
your
Plus/4
to
add
one
to
the counter.
If
the
counter
is
less
than
or
equal
to
the
end
value,
ihe
computer
returns
to
the
pro
gram
line
after
the
FOR
statement.
Otherwise,
your
Plus/4
continues
with
the
first
statemenl
after
the
NEXT
Example
using
a
FOR'NEXT
loop
10
PRINT."COUNTUP..."
20
FOR
J
-
1
TO
10
30
PRINT
"WE
HAVE";J
40
NEXTJ
50
PRINT
"WE
COUNTED
UP
TO";J
One
more
thing
about
FOR'NEXT
you
can
also
specify
a
STEP
value
in
the
FOR
statement.
Instead
of
adding
1
to
the
counter
variable,
your
Plus/4
adds
your
STEP
value.
If
you use
a
STEP
of
5
with
the
statement
FOR
M
-
10
TO
30,
for
example,
the
counter
would
count
10,
15,
20,
25,
30
after
each
loop
The
STEP
command
even
lets
you
count
back
wards
(by
using
a
negative
STEP
value).
77

Other manuals for Commodore Plus 4

Related product manuals