EasyManua.ls Logo

Commodore 128D - Page 274

Commodore 128D
427 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...
FOR/TO/STEP/
NEXT
—Define
a
repetitive
program
loop
structure.
FOR
variable
=
start
value
TO
end
value
[STEP
increment]
NEXT
variable
This
statement
works
with
the
NEXT
statement
to
set
up
a
section
of
the
program
(i.e.,
a
loop)
that
repeats
for
a
set
number
of
times.
This
is
useful
when
something
needs
to
be
counted
or
something
must
be
done
a
certain
number
of
times
(such
as
printing).
This
statement
executes
all
the
commands
enclosed
between
the
FOR
and
NEXT
statements
repetitively,
according
to
the
start
and
end
values.
The
start
value
and
the
end
value
are
the
beginning
and
ending
counts
for
the
loop
variable.
The
loop
variable
is
added
to
or
subtracted
from
during
the
FOR/NEXT
loop.
The
logic
of
the
FOR/NEXT
statement
is
as
follows.
First,
the loop
variable
is
set
to
the
start
value.
When
the
program
reaches
a
pro
gram
line
containing
the
NEXT
statement,
it
adds
the
STEP
incre
ment
(default
=
1)
to
the
value
of
the
loop
variable
and checks
to
see
if
it
is
higher
than
the
end
value
of
the
loop.
If
the
loop
variable
is
less
than
or
equal
to
the
end
value,
the
loop
is
executed
again,
start
ing
with
the
statement
immediately
following
the
FOR
statement.
If
the
loop
variable
is
greater
than
the
end
value,
the loop
terminates
and
the
program
resumes
immediately
following
the
NEXT
state
ment.
The
opposite
is
true
jf
the
step
size
is
negative.
EXAMPLE:
10
FOR
L
=
1
TO
10
20
PRINT
L
30
NEXT
L
40
PRINT
"I'M
DONE!
L
=
"L
This
program
prints
the
numbers
from
one
to
10
followed
by
the
mes
sage
I'M
DONE!
L
=
11.
The
end
value
of
the
loop
may
be
followed
by
the
word
STEP
and
another
number
or
variable.
In
this
case,
the
value
following
the
STEP
is
added
each
time
instead
of
one.
This
allows
counting
back
wards,
by
fractions,
or
in
increments
other
than
one.
The
user
can
set
up
loops
inside
one
another.
These
are
known
as
nested
loops.
Care must
be
taken
when
nesting
loops
so
the
last
loop
to
start
is
the
first
one
to
end.
u
u
u
u
u
266
BASIC
7.0
ENCYCLOPEDIA—Basic
Commands
and
Statements

Table of Contents

Other manuals for Commodore 128D

Related product manuals