bas7advr.hlp (Topic list)
GOSUB...RETURN Statement Details
  Syntax  Details  Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
GOSUB...RETURN branches to, and returns from, a subroutine.
 
GOSUB {linelabel1 | linenumber1}
.
.
.
RETURN [{linelabel2 | linenumber2}]
 
Usage Notes
    ■ BASIC's SUB and FUNCTION procedures provide a better-structured
      alternative to GOSUB...RETURN subroutines.
    ■ In addition to RETURN with no argument, BASIC supports RETURN with a
      line label or line number. This allows 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 can call a subroutine any number of times in a program. You also
      can call a subroutine from within another subroutine. How deeply
      you can nest subroutines is limited only by the available stack space
      (you can 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 return control to a
      statement only in the module-level code (not procedure-level code).
      See the Example.
    ■ A subroutine can contain more than one RETURN statement. A simple
      RETURN statement (without the linelabel2, linenumber2 option)
      in a subroutine makes BASIC branch back to the statement following
      the most recent GOSUB statement.
    ■ Subroutines can 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 SUB procedures delimited by SUB statements.
      For information on entering and exiting subroutines, see
      CALL Statement (BASIC Procedures).