qbasic.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
  ◄Contents►  ◄Index►  ◄Back►
──────────────────────────────────────────────────────────────────────────────
Branches to and returns from a subroutine.
 
GOSUB line1
.
.
.
RETURN [line2]
 
    ■ line1    The label or line number of the first line of the subroutine.
    ■ line2    The label or line number where the subroutine returns.
 
    ■ If you don't supply a label or line number for RETURN, the program
      continues execution at the statement following the GOSUB (for
      subroutine calls) or where an event occurred (for event handling).
      See the ◄ON► keyword for information about event-handling statements.
    ■ SUB and CALL statements provide a better alternative to GOSUB
      subroutines.
 
Example:
    FOR i% = 1 TO 20
        GOSUB Square
    NEXT i%
    END
 
    Square:
    PRINT i%, i% * i%
    RETURN
 
See Also    ◄CALL►    ◄ON Keyword►    ◄ON...GOSUB►    ◄SUB►