Hubbry Logo
logo
Goto
Community hub

Goto

logo
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Contribute something to knowledge base
Hub AI

Goto AI simulator

(@Goto_simulator)

Goto

In computer programming, goto is a control flow statement that transfers control to another line of source code. Unlike a function call that supports returning to the point of call, goto does not. The statement is denoted differently by programming language; sometimes as lower case (goto), upper case (GOTO) or case-insensitive, and sometimes as a single word or as two (i.e. GO TO).

A goto statement is included in a language, primarily, to provide access to the machine code jump instruction (a.k.a. branch or transfer), but due to potential problems with the use of jump semantics, languages have over time been augmented with other flow-control mechanisms intended to replace the need for and use of goto. Many modern languages do not include a goto statement at all. Many languages that include goto, restrict its use in order to limit the problems that its use might incur. Further, as its use is generally considered a poor choice, software developers tend to avoid using it even when using a language that provides it.

In general, use of goto is considered a poor choice as it leads to code with higher cognitive load and more bugs than code that uses more structured flow-control. The use of goto was common in the early days of computing, but via the concerted effort of the structured programming movement in the 1960s and 1970s, that aimed to replace goto with more structured flow-control, its use has declined significantly. None-the-less, goto is still used today, but generally limited to specific scenarios.

The structured program theorem proved that the goto statement is not necessary to write programs that can be expressed as flow charts; some combination of the three programming constructs of sequence, selection, and iteration are sufficient for any computation that can be performed by a Turing machine, with the caveat that code duplication and additional variables may be required.

Support of goto varies by language. Languages designed long ago tend to have unrestricted support and newer languages tend to have restricted or no support. For example, C does not permit a jump to a label in a different function.

C# and Visual Basic .NET both support goto. However, they do not allow jumping to a label outside of the containing scope, and respects object disposal and finally constructs, making it significantly less powerful and less dangerous than goto in other languages. They also make case and default keywords labels, whose scope is the enclosing switch statement. goto case or goto default is used as an replacement for implicit fallthrough, which is not allowed.

Many languages lack goto semantics. Java, has a reserved word goto but it is not usable, although compiled .class files generate goto and label statements.[clarification needed] Python does not support goto, although there are several joke modules that provide it. PHP did not support goto until version 5.3.

PL/I has a goto statement that unwinds the stack for an out-of-block transfer and does not permit a transfer into a block.

See all
statement invoking one-way transfer of program control in many languages
User Avatar
No comments yet.