72
•
If
the
initial value
to
be assigned
to
the
control. variable
is
greater
than
(or less
than for negative increments)
the
final value when
the
FOR statement
is
evaluated,
the
loop
is
not
executed, no value
is
assigned
to
the control, variable, and execution
proceeds with
the
first executable statement following
the
associated NEXT
statement.
•
If
the
value
of
the
STEP arithmetic expression
is
zero,
the
FOR loop
is
executed
an infinite number
of
times,
or
until
the
value
of
the
control variable
is
purposely
set beyond
the
specified final value.
• Transfer
of
control into
or
out
of
a FOR loop
is
permitted; however, a NEXT
statement cannot be executed unless its corresponding FOR statement has been
executed previously.
• FOR loops can be nested within one another as long
as
the
internal FOR loop
falls entirely within
the
external FOR loop (see the following example). Nested
FOR loops should not use
the
same control variable.
• The maximum number
of
nested FOR loops
is
15.
Example
The following example shows a simple FOR loop
that
increases the control variable
by 2 until the value
of
25
is
exceeded.
20 FOR I
= 1 TO
25
STEP 2
90
NEXT I
The next example shows the correct technique for nesting FOR loops. The inner
loop
is
executed 100 times for each execution
of
the
outer
loop.
10
FOR J = A TO B STEP C
150 FOR K
= 1 TO
100
250
NEXT K
300
NEXT J
/
/