Sharp MZ-700 Series Owner's Manual page 57

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

Advertisement

2. 3. 6. 8 ON-GOSUB
(abbreviated format: ON-GOS.)
Format
ON e GOSUB L r j < , Lr
2
, L r
3
,
, Lri >
e . . . Numeric variable, array element, or expression
Lri . Destination line numbers
Function
This statement branches execution to the subroutine beginning on one of the
line numbers following GOSUB, depending on the value of e. Operation of this
statement is basically the same as with the ON~GOTO statement, but all branches
are made to subroutines. Upon return from the subroutine, execution resumes
with the first executable statement following the ON~GOSUB statement which
made the call.
Example
Let's try using the ON~GOSUB statement in a scheduling program. The most
important point to note in the following program is that, a subroutine call is made
at line 180, even though line 180 itself is part of a subroutine (from line 170 to
190) which is called by line 90. Subroutines can be nested to many levels in this
manner.
1 0
20
3 0
4 0
5 0
60
F R
7 0
80
9 0
1 00
1 1 0
1 2 0
1 3 0
1 4 0
1 5 0
1 6 0
1 7 0
1
80
1 9 0
200
2 1 0
A S = "
E N G L
" : B $ =
D $ = "
S C I
" : E S =
G $ = "
H I S T
l!
: H $ =
J $ = "
B U S
" : K $ =
I N P U T " W H A T
D A Y ?
F O R
Z = 1
T O
7 : Y $ =
S A T " , 1 + 3 X C Z - 1 ) , 3 )
N E X T
Z
F O R
Y = 0
T O
4 : P R
N E X T
Y : P R I N T
O N
X
G O S U B
1 8 0 , 1 2 0 , 1 3 0 , 1 4 0 , 1 5 0 , 1 6 0 , 1 7 0
M A T H
" : C $ = "
F R E N
"
M U S
" : F $ = "
G Y M
A R T
" : I $ = "
G E O G
"
H
R M
" : P R I N T " B "
; X S
:
M I D S C " S U N M O N T U E W E D T H U
: I F
Y $ = X $
T H E N
X = Z
I N T
T A B C 5 + 6 X Y ) ; Y + 1 ;
P R
N T : G O T O
5 0
P R
N T " M O N
"
A S
B S
D S
G S
K S
R E T U R N
P R
N T " T U E
"
B $
E $
H S
H S
D S
R E T U R N
P R
N T " W E D
"
O S
C S
I S
A S
F S
R E T U R N
P R
N T " T H U
"
B S
D $
F S
G S
E $
R E T U R N
P R
N T " F R I
"
A S
D S
I S
C S
C S
R E T U R N
P R
N T " S A T
"
B S
G S
D S
K S
R E T U R N
F O R
Y - 1
T O
6
O N
Y
G O S U B
1 2 0 ,
P R I N T : N E X T
Y
R E T U R N
1 3 0 ,
1 4 0 ,
1 5 0 ,
1 6 0 ,
1 7 0
55

Advertisement

Table of Contents
loading

Table of Contents