Sharp MZ-700 Owner's Manual page 57

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

Advertisement

2. 3. 6. 8
ON~GOSUB
............................... (abbreviated format:
ON~GOS.)
I
Format
I
ONe GOSUB Lr
1
<,
Lr
2 ,
Lr
3
,
. . • . .
,
Lri
>
Function
Example
e . .
.
Numeric
variable,
array element, or expression
Lri
.
Destination line numbers
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.
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.
10 A$=
"
20 D$=
"
30 G$=
"
ENGL
.
" :
B$=
"
se
1
"
:
E$=
"
HI
ST
"
:
H$=
"
MATH
MUS
ART
":
C$=
"
":
F$=
"
":
I$=
"
FREN
GYM
GEOG
40 0$=
"
BUS
"
:K$=
"
H
RM
"
:PRINT
"[!)
"
50
INPUT
"WHAT DAY'?
"
;X$
60
FOR
Z=1
TO
7:Y$=MID$C
"S
UNMONTUEWEDTHU
FR
I
SAT
"
. 1
+3::!<CZ-1
), 3) : IF
Y$
=
X$
THEN X=Z
70 NEXT Z
80
FOR
Y=0
TO
4:PRINT
TAB
C5
+6::!<Y);Y+1;
90
NE XT
Y:PRINT
100 ON
X
GOSUB 180.120.130.140.150.1·60.170
110 PRINT:GOTO 50
·
120
PRINT
"
MON
";A$;
B$;D$;G$;K$:RETURN
130
PRINT
"
TUE
";
B$;E$;H$;H$;D$:RETURN
140 PRINT
"
WED
"
; C$; C$;
I$;
A$;
F$
:
RETURN
150
PRINT
"
THU
"
;B$;D$;F$;G$;E$:RETURN
1 60
PRINT
"
FR I
"
; A$;
D$; I$
;
C$; C$
:
RETURN
170 PRINT
"
SAT
";
B$;G$;D$
;K$:R
ETURN
180
FOR Y=1
TO
6
1 9
0
ON
Y
GOSUB 1 20.
1
30.
1
40.
1
50.
1
60.
1 7
0
200
PRINT:NE XT
Y
210
RETURN
- - - - - - - - - - - - - - - - -
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 5

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents