Sharp MZ-700 Basic Manual page 89

Disk basic interpreter
Hide thumbs Also See for MZ-700:
Table of Contents

Advertisement

91
5.1.8
Loop statements
FOR- TO
NEXT
10 FOR A
==
1 TO
The statement number
10
is a command to change
10
variable A and substitute for values from
1
to
10;
the
20
PRINT
A
30 NEXT A
value of the first A becomes 1. Because the value of A is
displayed on the
eRT
screen by statement number
20,
the
numeral 1 is displayed. Next, the value of A becomes 2 by
statement number 30, and this loop is repeated. The loop
is repeated in this way until the value of A becomes
10.
(At the point when the loop ends, the value 11 is entered
to A.)
10 FOR B
==
2 TO
A command to change variable B and substitute for values
8
STEP 3
from
2
to
8
in steps of
3
(statement number
10).
It is also
20
PRINT B
~ble
to make the
STEP
value negative and make the
30 NEXT
variable smaller each time.
An example of an overlay of the FOR - NEXT loops
10 FOR A=1 TO 3
(variables A and B). Note that B loop is placed inside A
20 FOR 8
S
1. 0 TO 30
J
'"I>
loop. Nesting of loops (doubling tripling ... ) is possible
30 PRINT A, 8
f f
'
,
40 NEXT 8
but the inner loop must be enclosed within the outer loop.
50 NEXT A
60 NEXT B, A
FOR - NEXT nesting must not
e~ed
15 levels.
70 NEXT A, B
t
It is possible, by the previous double loop, to group
Becomes
error.
statement numbers 40 and 50, as in statement number 60
at the left, into one NEXT statement. For an operand
such as shown in statement number 70, however, an error
occurs.

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mz-2z009

Table of Contents