Sharp PC-1403 Operation Manual page 150

Hide thumbs Also See for PC-1403:
Table of Contents

Advertisement

144
When
this
program
is run
it
prints the word 'HELLO'
one
time.
10 GOSUB 100
20
END
100 PRINT
"HELLO"
110 R~TURN
•¥f!,,1.u4
The group of statements
is
included in the program
at
some location where
they are
not
reached in the
normal sequence of
execution.
A frequent location is
after
the
END
statement which
marks
the
end
of
the main
program.
At those locations
in the main
body of the program-where
subroutines
are
to
be
executed-include
a
GOSUB state-
ment with an
expression which indicates
the
starting line
number
of
the subroutine.
The last line of the subroutine
must be a RETURN.
When GOSUB
i
s executed, the
COMPUTER transfers
control
to
the
indicated line number and processes the state-
ments until a RETURN is
reached.
Control
is
then transferred back to the statement
following the GOSUB.
A subroutine may
include
a
GOSUB. Subroutines may be
"nested"
in
this
fashion up
to 10 levels
deep.
The
expression
in
a
GOSUB
statement may not
include
a comma, e.g.,
'A(1, 2)'
cannot
be
used.
Since
there is
an ON
...
GOSUB
structure
tor
choosing
different
subroutines at
given locations in the program,
the
expression
usually
consists
of
just
the
desired
line
number.
When a numeric
expression
is
used,
it must eval
u
ate to a
valid line
number, i.e.,
1 to
65279,
or
an ERROR
4 will
occur.
••MW
When you
wish to
execute
the same group of statements several
times
i
n the
course
of
a
program or use
a previously
written set of
statements
in
several·
programs, it
is
convenient
to use
the BASIC capability
for
subroutines
using the GOSUB and
RETURN
verbs.
The
GOSUB verb
is
used
to execute a BASIC
subroutine.
1 GOSUB
expression
Abbreviations:
GOS.,
GOSU.
See
also:
GOTO,
ON
.. GOSUB,
ON ...
GOTO,
RETURN
Verbs
GOSUB

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents