GOTO

From ArticleWorld


GOTO is a typical instruction of high-level languages that causes a jump to another portion of the code. It is a fundamental flow-control instruction in programming, and can be found in most programming languages. It has received some acute criticism, thus making it unavailable in some newer high-level languages like Java.

Criticism

As programming became more and more formalized, a certain direction was inevitable. In the 1960s and 1970s, structured programming became the standard practice, as most programmers and computer scientists considered that structured programs are easier to debug and control.

Edsger Dijkstra described the reason why excessive usage of GOTO is a bad practice, in his letter "Go To Statement Considered Harmful". Dijkstra considered that, when it is used excessively, the GOTO statement makes programs difficult to analyze and verify.

However, many experienced programmers did not agree completely, as there are some cases where GOTO is the only straightforward solution. Donald Kunth described some of these situations in "Structured Programming with go to Statements". These are either such cases like breaking out of nested loops, or cases where a certain type of structure is not available.

GOTO-like statements

GOTO-like commands have appeared in other languages as well. One attempt to reduce the ambiguity of the typical GOTO statement is the computed GOTO statement. This can jump to several labels, using the value of an expression as the criteria for choosing the label. However, this does not solve the fundamental problem of the GOTO statement: one cannot tell what will be executed by simply looking at the statement. Such a statement is BASIC's ON GOTO, which works quite similar to C's switch statement.

The GOTO statement has been parodied in INTERCAL by using a COME FROM statement instead of GOTO.