EasyManua.ls Logo

Commodore VIC-20 - Page 35

Commodore VIC-20
308 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
. .
.
Format:
Abbreviation:
Screen
Display:
FOR
variable
=
F^.'Lrffi|o
Ff
start
TO
limit
[STEP
increment]
This
is
a
special
BASIC
statement
that
lets
you
easily
use
a
variable
as
a
counter.
You
must
specify
certain
parameters:
the
variable
name,
its
starting
value,
the
limit
of
the
count,
and
how
much
to
add
during
each
cycle.
Here
is
a
simple
BASIC
program
that
counts
from
1
to
10,
PRINTing
each
number
and
ENDing
when
complete,
and
using
no
FOR
statements:
100
L
=
1
110
PRINT
L
120
L
-
L
-f-
1
130
IF
L
<-
10
THEN
110
140
END
Using
the
FOR
statement,
here
is
the
same
program;
100
FOR
L
-
1
TO
10
110
PRINT
L
120
NEXT
L
130
END
As
you
can
seer
the
program
is
shorter
and
easier
to
understand
using the
FOR
statement.
Here
is
a
closer
look
at
the
parameters,
to
see
how
everything
works.
The
variable
can
be
any
numeric
variable
name
except
an
array
variable.
When
the
program
reaches
a
FOR
statement,
variable
is
set
to
the
value
of
start.
The
program
proceeds
with
the
statements,
until
a
statement
containing
the
word
NEXT
is
reached.
At
that
point,
increment
is
added
to
variabEe's
value.
The
STEP
is
optional,
and
if
there
is
no
STEP
shown
increment
is
assumed
to
be
4-1,
After
increment
has
been
added
to
variable,
the
vaJue
of
variable
is
compared
to
limit.
It
the
limit
has
not
been
exceeded
the
program
continues
with
the
line
after
the
FOR
statement.
If
the
limit
has
been
passed,
the
line
to
be
executed
is
the
line
following
the
NEXT
statement.
Note:
if
the
STEP
value
is
positive,
variable
will
exceed
limit
when
its
value
is
greater
than
limit,
and
if
the
STEP
value
is
negative,
the
variable
must
be
less
than
limit
to
end
the
count.
The
loop
will
always
be executed
at
least
once,
re
gardless
of
the
values
in
"start"
and
Lliimit".
19

Other manuals for Commodore VIC-20

Related product manuals