Futurebasic/Language/Reference/gosub

= GOSUB =

Syntax
GOSUB {lineNumber|&quot;statementLabel&quot;

Description
Executes the subroutine located at the indicated line number or statement label. The subroutine should include a  statement;   causes execution to continue at the statement following the   statement.

is an outdated method for executing routines; it's generally a better idea to encapsulate your routines in a  function. However, there are a couple of possible advantages to using :

 Routines called using  may execute somewhat faster than local functions.

You can create a "private" subroutine inside a local function, and use a  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.



Example: Subroutines can be executed in a "nested" fashion; i.e., one subroutine may call another. FB keeps track of where each  statement should "return" to.

program output:

Note: It is possible for a  statement inside a local function to jump to a subroutine located outside of that function; it's also possible for a   statement in "main" to jump to a subroutine located inside a local function. However, this kind of programming is not recommended, because the resulting switches in variable scope can produce unexpected results.