EasyManuals Logo

IBM 5100 Basic Reference Manual

IBM 5100
187 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #75 background imageLoading...
Page #75 background image
(
(
FOR control-var=arith-exp
TO
arith-exp
[STEP
arith-exp)
NEXT control-var
FOR
AND
NEXT
Together, a FOR statement and its paired NEXT statement delimit a FOR
loop-a
set
of
BASIC statements
that
can be executed a number
of
times. The FOR state-
ment marks the beginning
of
the loop and specifies the conditions
of
its execution
and termination. The NEXT statement marks
the
end of the loop.
The syntax
of
the
FOR and NEXT statements
is
as
shown:
FOR control-var=arith-exp
TO
arith-exp
[STEP
arith-exp)
NEXT control-var
where:
control-var
is
a simple arithmetic variable.
arith-exp are expressions
that
specify an initial value for
the
control variable,
the
final value
of
the
control value (at which execution
of
the
loop will end), and
the
amount
that
the control variable
will
increase after each execution
of
the loop.
If
STEP and
the
last arithmetic expression are omitted, an increment
of
1
is
assumed.
Upon execution
of
these statements,
all
expressions are evaluated. The initial value
of
the control variable
is
tested against
the
final value
of
the
control variable. If the
initial value
is
greater
than
(less
than for negative increments) the final value,
the
loop
is
not
executed. Instead,
the
value
of
the control variable
is
left unchanged and
control goes
to
the
statement following the NEXT statement.
If
the
loop
is
executed,
the
control variable
is
set equal
to
the
initial value, and
the
statements
in
the
loop are executed. When the NEXT statement
is
executed,
the specified increment
is
added
to
the control variable, which
is
then compared
with the specified final value. If
the
control variable
is
still less than (or greater
than, for negative increments)
or
equal
to
the
final value,
the
loop
is
executed
again and
the
cycle continues until an increment
is
made
that
renders
the
control
variable greater than (or less than for negative increments) the specified final value.
At
that
time, the control variable
is
set back
to
its last value and control falls
through
to
the first executable statement following
the
NEXT statement.
Notes About FOR and NEXT
The value
of
the
control variable can be modified by statements within
the
FOR
loop,
but
its initial value, final value, and increment are established during
the
initial execution of the FOR statement and are not affected by any
statement
within
the
FOR loop.
If
the
optional STEP arithmetic expression
is
omitted in the FOR statement,
the
increment value
is
automatically set
to
+1.
71

Table of Contents

Other manuals for IBM 5100

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM 5100 and is the answer not in the manual?

IBM 5100 Specifications

General IconGeneral
Release Year1975
RAM16 KB - 64 KB
Storage204 KB tape drive
Display5-inch CRT
Operating SystemAPL/BASIC
ProcessorIBM PALM (1.9 MHz)

Related product manuals