The goto statement is a programming construct found in many languages that performs an unconditional one-way transfer of control to another line of code. While goto was commonly used historically, its use has declined with the rise of structured programming since the 1970s due to goto being harder to understand. There is ongoing debate around appropriate uses of goto.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
47 views3 pages
Goto
The goto statement is a programming construct found in many languages that performs an unconditional one-way transfer of control to another line of code. While goto was commonly used historically, its use has declined with the rise of structured programming since the 1970s due to goto being harder to understand. There is ongoing debate around appropriate uses of goto.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3
Goto (goto, GOTO, GO TO or other case combinations, depending on the
programming language) is a statement found in many computer
programming languages. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control. The umped- to locations are usually identi!ed using labels, though some languages use line numbers. "t the machine code le#el, a goto is a form of branch or ump statement. $any languages support the goto statement, and many do not; see language support for discussion. The structured program theorem pro#ed that the goto statement is not necessary to write programs; some combination of the three programming constructs of se%uence, selection&choice, and repetition&iteration are su'cient for any computation that can be performed by a Turing machine, with the ca#eat that code duplication and additional #ariables may need to be introduced.()* "t machine code le#el, goto is used to implement the structured programming constructs. In the past there was considerable debate in academia and industry on the merits of the use of goto statements. +se of goto was formerly common, but since the ad#ent of structured programming in the ),-.s and ),/.s its use has declined signi!cantly. The primary criticism is that code that uses goto statements is harder to understand than alternati#e constructions. Goto remains in use in certain common usage patterns, but alternati#es are generally used if a#ailable. 0ebates o#er its (more limited) uses continue in academia and software industry circles.+sage(edit* goto label The goto statement is often combined with the if statement to cause a conditional transfer of control. I1 condition T234 goto label 5rogramming languages impose di6erent restrictions with respect to the destination of a goto statement. 1or e7ample, the 8 programming language does not permit a ump to a label contained within another function,(9* howe#er umps within a single call chain are possible using the setmp&longmp functions. 8riticism(edit* "lthough at the pre-":GO: meeting held in ),;,, 2ein< =emane> e7plicitly threw doubts on the necessity of GOTO statements, at the time no one paid attention to his remar>, including 3dsger 0i>stra, who would later become the iconic opponent of GOTO.(?* The ),/.s and ),@.s saw a decline in the use of GOTO statements in fa#or of the Astructured programmingA paradigm, with goto critici<ed as leading to Aunmaintainable spaghetti codeA (see below). Bome programming style coding standards, for e7ample the Gnu 5ascal 8oding Btandards, recommend against the use of GOTO statements. (citation needed* The CDhm-Eacopini proof (),--) did not settle the %uestion of whether to adopt structured programming for software de#elopment, partly because the construction was more li>ely to obscure a program than to impro#e it because its application re%uires the introduction of additional local #ariables.(F* It has, howe#er, spar>ed a prominent debate among computer scientists, educators, language designers and application programmers that saw a slow but steady shift away from the formerly ubi%uitous use of the GOTO. 5robably the most famous criticism of GOTO is a ),-@ letter by 3dsger 0i>stra called Go To Btatement 8onsidered 2armful.(?* In that letter 0i>stra argued that unrestricted GOTO statements should be abolished from higher- le#el languages because they complicated the tas> of analy<ing and #erifying the correctness of programs (particularly those in#ol#ing loops). The letter itself spar>ed a debate, including a AGGOTO 8onsidered 2armfulG 8onsidered 2armfulA letter(;* sent to 8ommunications of the "8$ (8"8$) in $arch ),@/, as well as further replies by other people, including 0i>straGs On a Bomewhat 0isappointing 8orrespondence.(-* "n alternati#e #iewpoint is presented in 0onald HnuthGs Btructured 5rogramming with go to Btatements, which analy<es many common programming tas>s and !nds that in some of them GOTO is the optimal language construct to use.(/* In their %uasi-standard boo> on the 8 programming language, 0ennis Iitchie and Crian Hernighan warn that goto is Ain!nitely abusableA, but also suggest that it could be used for end-of- function error handlers and for multi-le#el brea>s from loops.(@* These two patterns can be found in numerous subse%uent boo>s on 8 by other authors; (,*().*())*()9* a 9../ introductory te7tboo> notes that the error handling pattern is a way to wor> around the Alac> of built-in e7ception handling within the 8 languageA.(,* Other programmers, such as :inu7 Hernel designer and coder :inus Tor#alds or software engineer and boo> author Bte#e $c8onnell, also obect to 0i>straGs point of #iew, stating that GOTOs can be a useful language feature, impro#ing program speed, si<e and code clearness, but only when used in a sensible way by a comparably sensible programmer.()?* ()F* "ccording to computer science professor Eohn Iegehr, in 9.)?, there were about )..,... instances of goto in the :inu7 >ernel code.();* Other academics too> the completely opposite #iewpoint and argued that e#en instructions li>e brea> and return from the middle of loops are bad practice as they are not needed in the CDhm-Eacopini result, and thus ad#ocated that loops should ha#e a single e7it point.()-* 1or instance, Certrand $eyer wrote in his 9.., te7tboo> that instructions li>e brea> and continue Aare ust the old goto in sheepGs clothingA.()/* " slightly modi!ed form of the CDhm-Eacopini result allows howe#er the a#oidance of additional #ariables in structured programming, as long as multi-le#el brea>s from loops are allowed.()@* Cecause some languages li>e 8 donGt allow multi-le#el brea>s #ia their brea> >eyword, some te7tboo>s ad#ise the programmer to use goto in such circumstances.()9* The $IBI" 8 9..F standard bans goto, continue, as well as multiple return and brea> statements.(),* The 9.)9 edition of the $IBI" 8 standard has downgraded the prohibition on goto from Are%uiredA to Aad#isoryA status; the 9.)9 edition has an additional, mandatory rule that prohibits only bac>ward, but not forward umps with goto.(9.*(9)* 1ortran introduced structured programming constructs in ),/@ and in successi#e re#isions the relati#ely loose semantic rules go#erning the allowable use of goto were tightened; the Ae7tended rangeA in which a programmer could use a GOTO to enter and lea#e a still-e7ecuting 0O loop was remo#ed from the language in ),/@,(99* and by ),,; se#eral forms of 1ortran GOTO, including the 8omputed GOTO and the "ssigned GOTO, had been deleted from the language.(9?* Bome widely used modern programming languages, such as Ea#a and 5ython lac> the GOTO statement J see language support J though most pro#ide some means of brea>ing out of a selection, or either brea>ing out of or mo#ing on to the ne7t step of an iteration. The #iewpoint that disturbing the control Kow in code is undesirable may be seen in the design of some programming languages, for instance "da(9F* #isually emphasi<es label de!nitions using angle brac>ets. 3ntry )/.). in comp.lang.c 1"L list(9;* addresses the issue of GOTO use directly, stating
C++ Programming for Beginners: Get Started with a Multi-Paradigm Programming Language. Start Managing Data with Step-by-Step Instructions on How to Write Your First Program (2022 Guide for Newbies)