GLBasic User Manual

Main sections

GOSUB

GOSUB mysub

SUB mysub:
RETURN
ENDSUB



Use the GOSUB command to jump to code contained in a subroutine. At the end of the subroutine (defined by the 'ENDSUB' command), program control will be passed back to the command following the 'GOSUB' command.
See the SUB command for details on how to create a subroutine.

You can leave a subroutine prior to the ENDSUB command through use of the RETURN command. GOSUB can be called from within another subroutine.

Sample:
 
GOSUB draw
SHOWSCREEN
MOUSEWAIT
END

SUB draw:
PRINT "Eine Sub / A subroutine", 100, 100
RETURN // Jump back to GOSUB
PRINT "You won't see this!", 100, 150
ENDSUB


Output:
Eine Sub / A subroutine

See also...