Sharp MZ-700 Series Owner's Manual page 50

Personal computer
Hide thumbs Also See for MZ-700 Series:
Table of Contents

Advertisement

Example
FOR . . . NEXT loops may be nested within other FOR . . . NEXT loops. When
doing this, inner loops must be completely included within outer ones. Further,
separate control variables must be used for each loop.
1 0
F O R
X = 1
T O
2 0
F O R
Y = 1
T O
3 0
P R I N T
X X Y ;
4 0
N E X T
Y
5 0
P R I N T
6 0
N E X T
X
7 0
E N D
9 -
9 -
O h
o
o
n
o
o
3
o
F O R
F O R
F O R
A = 1
B = 1
C = 1
T O
T O
T O
o
5
7
N E X T
C , B , A
N E X T
C
N E X T
B
N E X T
A
When loops C, B, and A all end at the
same point as in the example above, one
NEXT statement may be used to indicate
the end of all the loops.
Incorrect example:
— T O R
J = 1
T O
1 0
p F O R
J = K
T O
K + S
- I — N E X T
J
X Different control variables
must be used in each loop.
F O R
1 = 1
T O
1 0
F O R
J = K
T O
K + 5
— N E X T
I
— N E X T
J
X Loops may not cross one
another.
Note
The syntax of BASIC does not limit the number of levels to which loops may be
nested; however, space is required to store return addresses for each level, so the
number of levels is limited by the amount of available free space.
The CLR statement (see page 59) cannot be used within a FOR . . . NEXT loop.
2.3.6.2
GOTO
Format
Function
Example
(abbreviated format: . . . G.)
GOTO Ln
Ln . . . . Destination line number
This statement unconditionally transfers program execution to the line number
specified in Ln. If Ln is the number of a line which contains executable statements
(statements other than REM or DATA statements), execution resumes with that
line; otherwise, execution resumes with the first executable statement following
line number Ln.
1 0
N = 1
2 0
P R I N T
N
3 0
N = N + 1
4 0
G O T O
2 0
5 0
E N D
•Transfers program execution to line 20.
48

Advertisement

Table of Contents
loading

Table of Contents