Misplaced Pages

GOSUB: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 22:51, 18 January 2018 editTitov (talk | contribs)5 editsm Support by Gambas← Previous edit Revision as of 20:32, 21 January 2018 edit undoTitov (talk | contribs)5 edits Gosub advantage: speedNext edit →
Line 2: Line 2:


The GOSUB command may be used to emulate ] in a BASIC dialect that does not support functions in its syntax. GOSUB is convenient for performing the same function several times in a BASIC program without duplicating the code.<ref>{{cite web|url=http://www.qbasicnews.com/qboho/qckadvr.gosubr.shtml|title=GOSUB...RETURN Statement Details.|date=1988|accessdate=2008-07-04|author=|publisher=]}}</ref> The GOSUB command may be used to emulate ] in a BASIC dialect that does not support functions in its syntax. GOSUB is convenient for performing the same function several times in a BASIC program without duplicating the code.<ref>{{cite web|url=http://www.qbasicnews.com/qboho/qckadvr.gosubr.shtml|title=GOSUB...RETURN Statement Details.|date=1988|accessdate=2008-07-04|author=|publisher=]}}</ref>

According to Benoît Minisini, the developer of ], the advantage of GOSUB ist speed, compared to the usage of separate methods.<ref>{{cite web|url=https://lists.gambas-basic.org/pipermail/user/2018-January/062618.html|title= Can JSON.Decode be faster?|date=2018|accessdate=2018-01-20|author=|publisher=}}</ref>


== RETURN == == RETURN ==
Line 12: Line 14:


== Support == == Support ==
Not all BASIC implementations support GOSUB or ON..GOSUB. For example, in ] GOSUB is considered as deprecated in favor of ]/FUNCTION, and is disabled by default.<ref>{{cite web |url=http://www.freebasic.net/wikka.php?wakka=KeyPgGosub |title=GOSUB |date=2008-05-08 |accessdate=2008-07-04 |publisher=FBWiki |quote=Gosub support is disabled by default in the -lang fblite unless the Option Gosub statement is used.}}</ref> In ], GOSUB and ON..GOSUB were removed when ] was released. In ] GOSUB as well as ON .. GOSUB were introduced in version 3.1 and 3.2. Not all BASIC implementations support GOSUB or ON..GOSUB. For example, in ] GOSUB is considered as deprecated in favor of ]/FUNCTION, and is disabled by default.<ref>{{cite web |url=http://www.freebasic.net/wikka.php?wakka=KeyPgGosub |title=GOSUB |date=2008-05-08 |accessdate=2008-07-04 |publisher=FBWiki |quote=Gosub support is disabled by default in the -lang fblite unless the Option Gosub statement is used.}}</ref> In ], GOSUB and ON..GOSUB were removed when ] was released. In Gambas GOSUB as well as ON .. GOSUB were introduced in version 3.1 and 3.2.


==See also== ==See also==

Revision as of 20:32, 21 January 2018

GOSUB is a command in many versions of the BASIC computer programming language. A GOSUB statement jumps to a line elsewhere in the program. That line and the following lines up to a RETURN are used as a simple kind of a subroutine without (sometimes with) parameters or local variables.

The GOSUB command may be used to emulate functions in a BASIC dialect that does not support functions in its syntax. GOSUB is convenient for performing the same function several times in a BASIC program without duplicating the code.

According to Benoît Minisini, the developer of Gambas, the advantage of GOSUB ist speed, compared to the usage of separate methods.

RETURN

A RETURN command resumes program flow from the point at which GOSUB was invoked.

Using GOSUB too many times, as in a loop or recursively, without corresponding RETURN statements, would typically cause a stack overflow. On the other hand, when the BASIC interpreter encounters a RETURN statement without a GOSUB it will emit a RETURN WITHOUT GOSUB error.

Computed GOSUB

A computed GOSUB statement, ON...GOSUB, exists in some BASIC dialects. The syntax of the statement is ON x GOSUB line1, line2, ... Computed GOSUB branches to one of several destinations based on the value of x. RETURN commands return program flow to the statement following ON..GOSUB.

Support

Not all BASIC implementations support GOSUB or ON..GOSUB. For example, in FreeBASIC GOSUB is considered as deprecated in favor of SUB/FUNCTION, and is disabled by default. In Visual Basic, GOSUB and ON..GOSUB were removed when VB.NET was released. In Gambas GOSUB as well as ON .. GOSUB were introduced in version 3.1 and 3.2.

See also

References

  1. "GOSUB...RETURN Statement Details". Microsoft. 1988. Retrieved 2008-07-04.
  2. "[Gambas-user] Can JSON.Decode be faster?". 2018. Retrieved 2018-01-20.
  3. "GOSUB". FBWiki. 2008-05-08. Retrieved 2008-07-04. Gosub support is disabled by default in the -lang fblite unless the Option Gosub statement is used.


Stub icon

This programming-language-related article is a stub. You can help Misplaced Pages by expanding it.

Categories: