Executes the subroutine located at the indicated line number or statement label. The subroutine should include a
return causes execution to continue at the statement following the
gosub is an outdated method for executing routines; it's generally a better idea to encapsulate your routines in a
local fn function. However, there are a couple of possible advantages to using
- Routines called using
gosub may execute somewhat faster than local functions.
- You can create a "private" subroutine inside a local function, and use a
gosub within that local function to call the subroutine. The variables used in the subroutine will have the same scope as the local function. This may be a good way to execute certain repetitive tasks within the local function.
Subroutines can be executed in a "nested" fashion; i.e., one subroutine may call another. FutureBasic keeps track of where each
return statement should "return" to.
print "First line."
print "Fifth line."
print "Second line."
print "Fourth line."
print "Third line."
gosub statement inside a local function cannot jump to a subroutine located outside of that function; similarly a
gosub statement in "main" cannot jump to a subroutine located inside a local function.
gosub programming is not recommended, a
local fn should be used as a replacement.
As of FutureBasic version 5.4.8, the new implementation of gosub/return does not support optimized compilation. If your code uses gosub/return and needs optimization, you will have to replace every subroutine by an ordinary local fn.
return; fn <userFunction>; local fn