Sharp OZ-707 Operation Manual - Page 97

ON expression GOSUB

Page 97 highlights

ON ... GOSUB p FORMAT: ON expression GOSUB line number 1} {line number 2} { *Iabel 1 ' *Iabel 2 ,... Abbreviation: O. GOS. See Also: GOSUB, GOTO, ON...GOTO PURPOSE: Executes one of a set of subroutines, depending on the value of a control expression. REMARKS: When ON ... GOSUB is executed, the expression between ON and GOSUB is evaluated and reduced to an integer. If the value of the integer is 1, control is transferred to line number 1 or *label 1 in the list, as in a normal GOSUB. If the expression is 2, control is transferred to line number 2 or *Iabel 2 in the list, and so forth. Note: Be sure to place a space just before the GOSUB command. Otherwise it may be regarded as a variable. If the expression is zero, negative, or larger than the number of line numbers provided in the list, no subroutine is executed and execution proceeds with the next statement or line of the program. An error occurs if the value of the expression is -32769 or less or 32768 or more. Use commas (,) to separate line numbers or *Iabels in the list. EXAMPLE: 10: INPUT A 20: ON A GOSUB 100,200,300 30: END 100: PRINT "FIRST" 110: RETURN 200: PRINT "SECOND" 210: RETURN 300: PRINT "THIRD" 310: RETURN An entry of 1 displays "FIRST'; 2 displays ·SECOND"; 3 dIsplays "THIRD". Any other entry does not produce any display. 182 183

  • 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

ON ... GOSUB
p
FORMAT:
ON expression GOSUB
{
line number
1}
{line number
2}
*Iabel 1
' *Iabel 2
,...
Abbreviation:
O.
GOS.
See Also:
GOSUB, GOTO, ON ... GOTO
PURPOSE:
Executes one of a set of subroutines, depending
on
the value of a
control expression.
REMARKS:
When ON ... GOSUB
is
executed, the expression between
ON
and
GOSUB is evaluated and reduced
to
an
integer. If the value of the
integer is
1,
control
is
transferred
to
line number 1 or *label 1 in the
list, as
in
a normal GOSUB. If the expression is 2, control
is
transferred to line number 2 or *Iabel 2
in
the list, and so forth.
Note:
Be
sure to place a space just before the GOSUB command. Otherwise
it may be regarded
as
a variable.
If the expression is zero, negative, or larger than the number of line
numbers provided
in
the list, no subroutine
is
executed and execution
proceeds with the next statement or line of the program.
An
error occurs
if
the value of the expression is
-32769
or less or
32768 or more.
Use commas
(,)
to
separate line numbers or *Iabels in the list.
182
EXAMPLE:
10: INPUT A
20:
ON
A
GOSUB 100,200,300
30:
END
100: PRINT "FIRST"
110: RETURN
200: PRINT "SECOND"
210: RETURN
300: PRINT "THIRD"
310: RETURN
An entry of 1 displays "FIRST'; 2 displays ·SECOND"; 3 dIsplays "THIRD". Any other
entry does not produce any display.
183