Sharp OZ-707 Operation Manual - Page 76

s,lalles, start~d

Page 76 highlights

GOSUB ... RETURN FORMAT: GOSUB {line number} *Iabel RE+URN {line number} *Iabel Abbreviation: GOS. RE. See Also: GOTO, ON...GOSUB PURPOSE: Diverts program execution to a BASIC subroutine. REMARKS: When you wish to execute the same group of statements several times in the course of a program, it is convenient to use the BASIC capability for subroutines using GOSUB and RETURN . The group of statements is included in the program at some location where they are not reached in the normal sequence of execution. A common location is following the END statement that marks the end of the main program. At each location in the main body of the program where a subroutine is to be executed, include a GOSUB statement with a line number or *Iabel that indicates the starting line number of the subroutine. The last line of each subroutine must be a RETURN . When GOSUB is executed, the Card transfers control to the indicated line number or *Iabel and processes the statements until a RETURN is reached . Control is then transferred back to the statement following the GOSUB. If a line number or *Iabel follows RETURN, control will return to the line number or *Iabel. Subroutines may be "nested" up to 36 levels deep. (See Appendix E.) Since there is an ON ...GOSUB structure for choosing different subroutines at given locations in the program, the expression in a GOSUB statement usually consists of just the desired line number or *Iabel. 140 p GOTO o FORMAT: GOTO {line number} lI

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128

GOSUB ... RETURN
FORMAT:
GOSUB {line number}
*Iabel
RE+URN {line number}
*Iabel
Abbreviation:
GOS. RE.
See
Also:
GOTO, ON ... GOSUB
PURPOSE:
Diverts program execution to a BASIC subroutine.
REMARKS:
When you wish
to
execute the same group of statements several times
in
the course of a program, it
is
convenient to use the BASIC capability
for subroutines using GOSUB
and
RETURN .
The group of statements is included
in
the program at some location
where they are not reached
in
the normal sequence of execution. A
common location
is
following the
END
statement that marks the end of
the main program.
At each location
in
the main body of the program where a subroutine
is
to be executed, include a GOSUB statement with a line number or
*Iabel that indicates the starting line number of the subroutine. The last
line of each subroutine must be a RETURN.
When GOSUB
is
executed, the Card transfers control
to
the indicated
line number or *Iabel and processes the statements until a RETURN
is
reached. Control is then transferred back to the statement following the
GOSUB. If a line number or *Iabel follows RETURN, control will return
to the line number or *Iabel.
Subroutines may
be
"nested" up to 36 levels deep. (See Appendix E.)
Since there
is
an
ON
..
.GOSUB structure for choosing different
subroutines at given locations
in
the program, the expression in a
GOSUB statement usually consists of just the desired line number or
*Iabel.
140
GOTO
FORMAT:
GOTO {line number}
lI<Iabel
Abbreviation:
G.
See
Also:
GOSUB,
ON
...
GOTO, RUN
PURPOSE:
Transfers program control to a specified line number or *Iabel.
REMARKS:
GOTO transfers control from one location
in
a BASIC program to
an
other location. Unlike GOSUB, GOTO does not "remember" the
lo
cation from which the transfer occurred.
Usually, a program is executed sequentially from the
s",lalles~
line
nu
mber. However, execution can be transferred to the line
With
the
giv
en
line number or *Iabel. Program execution can be
.start~d
fro~
the specified line by specifying a GOTO statement as direct Input
In
the
RUN
mode. The transfer destination is specified by entering the
li
ne
number or *Iabel after the GOTO command.
E
xample:
GOTO 40
GOTO*AB
Jumps
to
line 40
Jumps to the line with label
*AB
If the specified line number or *Iabel does not exist, an error occurs.
If two or more identical *Iabels are included in a program, program
execution transfers to the line with the lower line number.
EXAMPLE:
10: INPUT
A$
20
:
IF
A$
=
"yo
GOTO
50
30: PRINT "NO"
40
: GOTO 60
50: PRINT "YES"
60:
END
p
o
Th
is
program
prints
"YES
" if a "
Y"
is
entered
and
prints
"
NO"
if
anything
else
is
entered
.
141