EasyManua.ls Logo

Radio Shack TRS-80 Model III - Page 167

Radio Shack TRS-80 Model III
274 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
Loading...
BASIC
The variables and expressions in line 20 are evaluated
once
and these
values
become constants for the FOR-NEXT-STEP loop. Changing the variable values
later
has no effect on the loop.
FOR-NEXT loops may
be
'
'nested"
:
LOOP'
10
FOR
I
=
1
TO 3
20
PRINT
"OUTER
LOOP"
30
FOR J
=
1 TO 2
40
PRINT
ii
INNER
50 NEXT J
60 NEXT I
RUN
OUTER
LOOP
INNER LOOP
INNER
LOOP
OUTER
LOOP
INNER
LOOP
INNER
LOOP
OUTER LOOP
INNER
LOOP
INNER LOOP
READY
Note
that
each NEXT statement specifies the appropriate counter variable; however,
this is just
a
programmer's convenience to
help keep track of
the nesting
order. The
counter variable may
be
omitted from the NEXT statements.
But
if
you do use the
counter variables, you
must use
them in the
right
order; i.e.
, the
counter
variable
for the innermost loop
must
come first.
It is also
advisable
to specify
the counter
variable
with NEXT statements when
your
program allows branching to program lines outside the FOR-NEXT loop.
Another option with nested NEXT statements is to use a counter variable list.
Delete line
50
from the above program
and
change line 60:
60 NEXTJ,!
Loops may
be
nested
3-deep, 4-deep, etc. The
only limit is the
amount
of
memory
available.
157

Other manuals for Radio Shack TRS-80 Model III

Related product manuals