Revision as of 16:50, 10 September 2014 editOMPIRE (talk | contribs)Extended confirmed users5,852 editsNo edit summary← Previous edit | Latest revision as of 01:35, 10 January 2021 edit undoApokrif (talk | contribs)Extended confirmed users, Pending changes reviewers28,429 edits ←Changed redirect target from BASIC to BASIC#Program flow controlTag: Redirect target changed | ||
(9 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
#REDIRECT ] | |||
'''GOSUB''' is a command in many versions of the ] computer ]. A GOSUB statement jumps to a line elsewhere in the program. That line and the following lines up to a ] are used as a simple kind of a ] without (sometimes with) parameters or local ]. | |||
⚫ | ] | ||
{{R from subtopic}} | |||
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> | |||
{{Rwh}} | |||
== RETURN == | |||
A ] command resumes ] 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 ]. On the other hand, when the BASIC interpreter encounters a RETURN statement without a GOSUB it will emit a <code>RETURN WITHOUT GOSUB</code> error. | |||
== Computed GOSUB == | |||
A computed GOSUB statement, <code>ON...GOSUB</code>, exists in some BASIC dialects. The syntax of the statement is <code>ON x GOSUB line1, line2, ...</code> 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 ] 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. | |||
==See also== | |||
* ] | |||
==References== | |||
{{reflist}} | |||
⚫ | ] | ||
{{compu-lang-stub}} |
Latest revision as of 01:35, 10 January 2021
Redirect to:
- From a subtopic: This is a redirect from a subtopic of the target article or section.
- If the redirected subtopic could potentially have its own article in the future, then also tag the redirect with {{R with possibilities}} and {{R printworthy}}.
- With history: This is a redirect from a page containing substantive page history. This page is kept as a redirect to preserve its former content and attributions. Please do not remove the tag that generates this text (unless the need to recreate content on this page has been demonstrated), nor delete this page.
- This template should not be used for redirects having some edit history but no meaningful content in their previous versions, nor for redirects created as a result of a page merge (use {{R from merge}} instead), nor for redirects from a title that forms a historic part of Misplaced Pages (use {{R with old history}} instead).