Retro Rocket OS
BASIC-Powered Operating System
Loading...
Searching...
No Matches
RETURN Keyword
RETURN

Returns from a subroutine that was entered with GOSUB. Execution resumes at the statement after the GOSUB call.

Note
RETURN is only valid while servicing a GOSUB.
Using RETURN outside a GOSUB context is an error.
GOSUB/RETURN are kept for compatibility and are deprecated.
Prefer structured procedures: DEF PROCname(...) ... ENDPROC, called with PROCname(...).

Behaviour

  • RETURN takes no arguments.
  • Nested subroutines are supported: each GOSUB must eventually reach a RETURN, which returns to its own caller.
  • RETURN is not used to exit PROC or FN:
    • Procedures end with ENDPROC.
    • Functions return a value on a line that begins with =.

Examples (line numbers permitted)

Simple subroutine

10 PRINT "Start"
20 GOSUB 1000
30 PRINT "Back in main code"
40 END
1000 PRINT "Inside subroutine"
1010 RETURN

Nested GOSUBs

10 PRINT "Main"
20 GOSUB 1000
30 PRINT "Done"
40 END
1000 PRINT "First level"
1010 GOSUB 2000
1020 PRINT "Back to first level"
1030 RETURN
2000 PRINT "Second level"
2010 RETURN

Error: RETURN without GOSUB (do not do this)

10 RETURN

See also