Loop In A Loop - Sharp MZ-80A Owner's Manual

Hide thumbs Also See for MZ-80A:
Table of Contents

Advertisement

38
Loop in a
loop
Alice
is doing her
homework. She
is preparing
a multiplication
table using the
computer,
and a program which
contains
double
FOR
....
NEXT
statements.
10
20
30
40
50
60
FOR X
=
1 TO 9
FOR Y
=
1 TO 9
PRINT X
*
Y
;
NEXTY
PRINT
NEXT X
Loop Y
Loop
X
In the FOR
....
NEXT loop for variable
X,
the FOR
....
NEXT
loop for variable Y
is included. Variables
X
and
Y vary from
1 to
9, respectively, and 1 is
substituted for
variable
X
to execute variable
Y
loop.
In
other
words,
with
variable
X
remaining
at
1, variable
Y
varies
1,2,3
.....
to 9,
and each
time, the multiplication
product with variable X
is
displayed
at
line number 30. When varialbe
Y
reaches
9,
a line feed is executed
at line
number
50, and at line
number
60, variable
X
is then
2.
The FOR
....
NEXT
loop can be used double, triple,
etc.,
up
to
15.
What must be
observed, however, is that
loops
are never
crossed and no jump into the loop by
means of GOTO
is
allowed.
Thus, loop C is completely included in loop B, while loop B
is completely
included in loop A. As shown on the
right, one word
NEXT
can be used for all three loops.

Advertisement

Table of Contents
loading

Table of Contents