Programmer Guide/Command Reference/GOSUB: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
  GOSUB <var>subrlabel</var> [<var>arguments</var>]
  GOSUB <var>subrlabel</var> [<var>arguments</var>]
Call the local subroutine at <var>subrlabel</var> label. The subroutine will get a ''copy'' of the current execution environment, meaning that it can "see" all current variables, but that any changes to them will be local to the subroutine. So, there is no danger of the subroutine changing the caller's variable environment - but there is also no way of doing this intentionally. Don't forget to finish your subroutine with an appropriate [[Programmer_Guide/Command_Reference/EXIT|EXIT]] statement.
Call the local subroutine at <var>subrlabel</var> label. Calling a local subroutine is like starting a new macro, but the execution begins at the label subrlabel and not with the first line of the macro code. The subroutine will get an own execution environment and an own local variable space. Use the command [[Programmer_Guide/Command_Reference/EXIT|EXIT]] to end the subroutine and to return a result to the caller.


Note that if you really, really must change the variables of the caller, you may use the <code>[[Programmer Guide/Command Reference/GOSUBX|GOSUBX]]</code> statement.
Note: The command [[Programmer Guide/Command Reference/GOSUBX|GOSUBX]]</code> works like this command, but the called subroutine uses the same ''local variable environment'' as the caller.
 
See also:
[[Programmer Guide/Command Reference/GOTO]],
[[Programmer Guide/Command Reference/DISPATCH]],
[[Programmer Guide/Command Reference/MACRO]]

Revision as of 08:41, 25 January 2016

GOSUB subrlabel [arguments]

Call the local subroutine at subrlabel label. Calling a local subroutine is like starting a new macro, but the execution begins at the label subrlabel and not with the first line of the macro code. The subroutine will get an own execution environment and an own local variable space. Use the command EXIT to end the subroutine and to return a result to the caller.

Note: The command GOSUBX works like this command, but the called subroutine uses the same local variable environment as the caller.

See also: Programmer Guide/Command Reference/GOTO, Programmer Guide/Command Reference/DISPATCH, Programmer Guide/Command Reference/MACRO

Navigation menu

Personal tools