Encyclopedia  |   World Factbook  |   World Flags  |   Reference Tables  |   List of Lists     
   Academic Disciplines  |   Historical Timeline  |   Themed Timelines  |   Biographies  |   How-Tos     
Sponsor by The Tattoo Collection
Goto
Main Page | See live article | Alphabetical index

Goto

GOTO is a command found in many programming languages which instructs the computer to jump to another point in the computer program. It is the fundamental operation which can be used for transfer of control from one part of a program to another, and most compilers will translate other flow control statements into GOTOs.

GOTO is found in FORTRAN, Algol, COBOL, SNOBOL, BASIC, C, C++, Pascal, Perl and many other languages, particularly assembly languages. In the assembly languages, the GOTO command is usually called BRA (from "branch"), JMP or JUMP, and is often the only way of organizing program flow. However GOTO is not found in all programming languages. In certain languages, such as Java, "goto" is a reserved word. In the parody programming language INTERCAL, COME FROM is used instead.

Unlike a function call, a GOTO does not demand any preparation or restructuring of the code. As a result, it becomes very easy to produce inconsistent, incomplete and generally unmaintainable spaghetti code. Consequently, as structured programming became more prominent in the 1960s and 1970s, numerous computer scientists came to the conclusion that programs should always use the structured flow commands (loops, if-then statements, etc.) in place of GOTO. However, others believed that even though the use of GOTO is often bad practice, there are some tasks that cannot be straightforwardly accomplished in many programming languages without the use of GOTO statements, such as exception handling. Java avoids this issue by using try-catch blocks for exception handling.

One famous criticism of GOTO is a letter by Edsger Dijkstra called Go To Statement Considered Harmful (Communications of the ACM 11 (3), 147-148, March 1968). In that letter Dijkstra argued that unrestricted GOTO statements should be abolished from higher-level languages because they complicated the task of analyzing and verifying the correctness of programs (particularly those involving loops). Donald Knuth's Structured Programming with goto Statements (Computing Surveys 6 (4), 261-301, December 1974) considers some of the places where GOTO may be the appropriate tool. Generally these are in situations where a particular programming structure is not available. In these cases, GOTO can generally be used to emulate the desired structure, since it is one of the fundamental building blocks of programming.

See also

External links