EasyManua.ls Logo

Apple IIe - Page 70

Apple IIe
320 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...
70
Apple lie Users
Handbook
However
, this
method
is
very cumbersome. This
problem
could
be
solved
much
more
efficiently
through
the
use
of
a
FOR,
NEXT
loop
as
shown
below
.
100
FOR
A=
1
TO
20
200
X=AA2
300
PRINT X
400
NEXT
A
500
END
The sequence
of
statements
from
100
to
400
is
known
as
a
loop.
When
the
computer
encounters
the
FOR
statement
i~
line
100
,
the
variable
A
is
set
to
1. X
is
then
calculated
and
displayed
in
lines
200
and
300.
The
NEXT
statement in
line
400
will
request
the
next value
for
A.
Execution returns
to
line
100
where
the
value
of
A
is
incremented
by 1
(to
2)
and
then
compared
to
the
value
appearing after
TO.
Since
the
value
of
A
is
less
than that
value,
the
loop
will
be
executed again
with
the
value
of
A
set
at 2.
The
loop
will
continue
to
be executed
until
A attains a value
greater than
20.
When
this occurs,
the
statement
following
the
NEXT
statement
will
be executed.
In
our
preceding
example, A
is
known
as
an
index
variable.
If
the
optional
keyword
STEP
is
not
included
with
the
FOR
statement,
the
index
variable
will
be
incremented
by 1 every
time
the
NEXT
statement
is
executed.
STEP
can be
included
at
the
end
of
a
FOR
statement
to
change
the
value by
which
the
index
variable
is
incremented
. The
integer
appearing after
STEP
is
the
new
increment.
For example,
if
our
preceding
example
were changed
as
follows,
100
FOR
A = 1
TO
20
STEP
2
200
X=AA2
300
PRINT X
400
NEXT
A
500
END

Other manuals for Apple IIe

Related product manuals