Table of Contents

GOSUB

PET VIC-20 C64 C16 Plus/4 C128 X16 M65

Syntax

GOSUB <label>

The GOSUB command calls a subroutine marked by a label. RETURN will pass control back to the caller.

Note

Unlike Subroutines, labelled code points do not start a new local scope.

Example

' ** subroutines **
GOSUB first_routine
END
 
first_routine:
  PRINT "hello world"
  GOSUB second_routine
  RETURN
 
second_routine:
  PRINT "and hello again"
  RETURN

Warning

Make sure you use the END command before your routines if you don't want them to be executed in the normal program flow (like in the example above).