Calling a subroutine

gosub

Call a subroutine


SYNTAX

gosub label

The gosub command causes program control to pass to the statement at the label indicated. The label is normally the start of a section of code forming a subroutine with a return statement as its last command. The return statement returns control to the statement immediately following the gosub command.

The line label itself is terminated with a colon. This colon informs the compiler that the line is a label, and is not part of the label name.

Note

Each subroutine should be exited using a return statement. The use of the goto command should be avoided. Repeated use of goto to exit subroutines causes a stack overflow error.

It is possible for subroutines to call themselves recursively. However, it should be remembered that all variables within the subroutine are global, and are not local to that recursion.

A subroutine cannot take arguments, nor can it have locally declared variables, nor can it return a value. To do any of these things you must use a function.


EXAMPLE

    gosub SET_NAME_ADDRESS
    ...
SET_NAME_ADDRESS:
    tmp.Name = "Hyperbole Software Systems"
    tmp.Addr[1] = "Metaphor House"
    tmp.Addr[2] = "38, Straight Street"
    tmp.Addr[3] = "London SW1 2AX"
    return

RELATED TOPICS

!function

return