ON-G05UB
ON
numeric-expression
{GOSUB}
line·numberl./ine·numberl
...
GO
SUB
The
ON
-GOSUB
statement
is used with the
RETURN
statement
to tell the
computer
to
perform
one
of
several
subroutines.
uepeuuiug,
Ull
lhe
value
of
a numcriccxprc33ion,
and
then
go
back
to the
main
program sequence.
The
computer
first
evaluates
the numeric'expression
and
converts
the result
to
an
integer,
rounding
if necessary.
This
integer tells the
program which
subroutine
line-number in the ON -GOSUB
statement
to perform next. If the value
of
the
numeric-expression
is
1. the
computer
will proceed to the first line-number listed
in
the
ON
-GOSUB
statement.
If
the value is
2.
the
computer
will
branch
to
the
se~onrl
line'
number
given.
and
so on.
Additionally the
computer
will save the
next
line
number
following
the
ON
-GOSUB
statement
and
return
to this point after performing
the subroutine.
The
subroutme
must
contain
a
RETURN
statement
to signal the
computer
to go
back
to the
saved
line
number
and
continue the program from
that
statement.
Otherwise,
the
program
will continue until it
reaches
the end,
as
jf
a
GOTO
was
performed
instead
of
a
GOSUB.
If
the
rounded
value of the numeric-expression is less
than
1 or
greater
thau
the
number
of
line
numbers
in
the
ON
-GOSUB
statement,
the
program
will
terminate
with the
message
"BAD
VALUE
IN
xx."
If
the
line·number
listed is not a valid program line, the
message
"BAD
LINE
NUMBER"
will
print
when
you
perform
the
statement.
User's
Reference
Guide
Examples:
>NEW
>100
INPUT
"CODE=?":CODE
>110
IF
CO~E=Q
T~FN
;>90
>120
INPUT
"HOURS=?":HOURS
>130
ON
CODE
GOSUB
170,200,23
0,260
>140
PAY=RATF*HOURS+BASEPAY
>150
PRINT
"PAY
IS $";PAY
>160
GOTO
100
>170 RATE=3.10
>1RO
RA<;;EPAY=5
>190
RETURN
>200 RATE=4.25
>210
BASEPAY=25
>220 RnURN
>230
RATE=10
>240
BASEPAY=50
>250
RETURN
>;>60
RATE=25
>270 BASEPAY=100
>280
RETURN
>290
END
>RUN
CODE=?4
HOURS=?40
PAY
IS $
1100
CODE=?2
HOURS=?37
PAY
IS
S
182.25
CODE=?3
HOURS=?35.75
PAY
IS $
407.5
CDDE=?1
HOURS=?40
PAY
IS $
129
CODE=?9
**
DONE
**
>RU
N
CDDE=?5
HOURS=?40
*
BAD
VALUE
IN
130
>130
ON
CODE
GOSUB
170,200,23
0,600
;>KUN
CODE=?4
HOURS=?40
~
BAD
LINE
NUMBCR
IN
130
II-II?