qb45advr.hlp (
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
GOSUB...RETURN Statement Details
◄QuickSCREEN► ◄Details► ◄Example► ◄Contents► ◄Index►
──────────────────────────────────────────────────────────────────────────────
GOSUB...RETURN Statement Details
Syntax
GOSUB {linelabel1 | linenumber1}
[statements]
RETURN [linelabel2 | linenumber2]
Argument Description
linelabel1, linenumber1 The line number or line label that is the
first line of the subroutine.
linelabel2, linenumber2 The line label or line number where the
subroutine returns.
Note: BASIC's SUB and FUNCTION procedures provide a more well-structured
alternative to GOSUB...RETURN subroutines.
In addition to RETURN with no argument, BASIC supports RETURN
with a line label or line number allowing a return from a subroutine
to the statement having the specified line number or label, instead
of returning to the statement after the GOSUB statement. Use
this line-specific type of return with care.
You may call a subroutine any number of times in a program. You may
also call a subroutine from within another subroutine. How deeply
you can nest subroutines is limited only by the available stack space
(you may increase the stack space with the CLEAR statement).
Subroutines that call themselves (recursive subroutines) can easily
run out of stack space. RETURN with a line label or line number
can only return control to a statement in the module-level code not
procedure-level code. See the example program below.
A subroutine may contain more than one RETURN statement. Simple
RETURN statements (without the linelabel2, linenumber2 option) in a
subroutine make BASIC branch back to the statement following the most
recent GOSUB statement.
Subroutines may appear anywhere in the program, but it is good
programming practice to make them readily distinguishable from the
main program. To prevent inadvertent entry into a subroutine, precede
it with a STOP, END, or GOTO statement that directs program control
around the subroutine.
----- Important -----
The preceding discussion of subroutines applies only to the targets of
GOSUB statements, not subprograms delimited by SUB statements. Entering
and exiting SUB blocks with GOSUB...RETURN statements is not supported.
---------------------