RETURN Statement

The RETURN statement returns program control from a subroutine to the main program or to a specified statement label.

Format

RETURN [TO label]

Parameter(s)

TO label

Passes control of the specified program to the line marked by the specified label.

Description

A RETURN statement terminates a subroutine. Without the TO clause, a RETURN statement returns execution to the line following the GOSUB or CALL statement. The TO clause may be used to exit only an internal subroutine called by a GOSUB statement.

NOTE

Care should be exercised when the TO clause is used. Any other GOSUBs or CALLs that were active at the time the GOSUB was executed remain active, and errors may result.

Example

In this application, a subroutine for performing all the final calculations in an accounting program is called CALCULATE, and the subroutine for exiting the program is called EXIT. The EXIT subroutine clears the screen, calls another subroutine called REPORT to print out a final report of transactions, and prints "--EOJ" before exiting.

PRINT "CONTINUE WITH ALL CALCULATIONS?":

   INPUT ANS,1

   IF ANS = "Y" THEN

      GOSUB CALCULATE

   END ELSE

      GOSUB EXIT

   END

      .

      .

      .

   STOP

EXIT:

   PRINT @(-1) : "REPORT OF TRANSACTIONS:":

   GOSUB REPORT

   PRINT "-- EOJ"

   STOP

   RETURN

CALCULATE :

      .

      .

      .

RETURN

See Also

Statement and Function Reference