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>label</var> [<var>arguments</var>]
  GOSUB <var>subrlabel</var> [<var>arguments</var>]
Call the local subroutine at <var>label</var> label. The call to a subroutine is like starting a macro, but instead of calling a new macro source code, a copy of the calling macro is created and the execution of the copy is started at label. A subroutine must be finished with the [[Programmer_Guide/Command_Reference/EXIT|EXIT]] command (= return).
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.
 
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.

Revision as of 17:39, 23 March 2011

GOSUB subrlabel [arguments]

Call the local subroutine at subrlabel 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 EXIT statement.

Note that if you really, really must change the variables of the caller, you may use the GOSUBX statement.

Navigation menu

Personal tools