Goto
The instruction goto (of English go to , in French to go to ) is a instruction present in many computer programming languages. It is used to carry out unconditional jumps in a program. The execution is returned towards a label or label , which is either a given number of line, or a label declared, according to the language.
The instruction goto, directly inherited the instructions of jump of the machine languages, was necessary in the primitive languages (FORTRAN II/IV, BASIC) like basic instruction making it possible to carry out loops and other structures of controls.
Since the revolution of the structured Programming of the Years 1970, the instruction goto is hardly appreciated modern programmers, because it often makes the programs more difficult to include/understand and maintain (one speaks in this case about Programmation spaghetti ). One more generally uses of the structures like the conditional jumps ( if. then. if not. ) or them loops ( for , as long as , etc) which form integral part of all the modern computer programming languages.
In certain languages, other instructions carry out unconditional jumps and replace some uses of the instruction goto. It is the case of the instructions like continue or break, which one finds in the languages derived from the C, and of the exceptions.
Languages
The instructiongoto (or equivalent) appears in particular in the languages suivants :
Emulation
In 1966, the Theorem of Böhm and Jacopini showed that any comprising program of the goto could be transformed into program using only conditional connections (if, then, else) or loops (while condition do instructions ), possibly by duplicating portions of codes and/or by using intermediate variables. Later the two authors showed that the conditional connections could them same being replaced by loops.
Method of Jacopini
Although languages do not comprise a goto, certain programmers are convinced (wrongly or rightly) of the interest to employ them. It then developed a method of emulation. Concretely, it is a question of placing the label in a variable and of seeking it during all the code. Thus, one a:
% Beginning of program goto = -1 % not of jump while (goto < 0) { % zone without the wording } yew (goto == 0) { % All the part of the wording 0 } else yew (goto == 1) { % All the part of the wording 1 } %… else yew (goto == N ) { % All the part of the wording N }
One sees initially that the wording can be chains or numbers, including expressions. It is possible to further go and not to be restricted with a whole of points to represent the wording. One can thus represent them by whole of intervals, plans and hyperplanes. The disadvantage of this method is that it should be waited until all the instructions of the loops while are finished so that the unconditional jump is carried out.
Exceptions
The functionssetjmp and longjmp, available on certain operating systems, also make it possible to emulate the instruction goto. But these instructions of unconditional jump are especially used to establish a management system of the exceptions.
The use of exception is for example a pattern running in Python to leave a double loop:
Anecdotes
The first versions of ALGOL 60 carried out in France had translated all the key words of the language and quite naturally the instruction goto was called will allera .
Goto is an authentic Japanese patronym and Donald Knuth joked on this poor Mr Goto that everyone rejected.
See too
-
Goto Perl Article published in Linux Magazine 72, May 2005.
- Go To Statement Considered Harmful Edsger Dijkstra (1968)
- structured programming with goto statements (pdf) Donald Knuth (1974)
| Random links: | Bignon-Mirabeau | Aditî | Bomarzo | Al Rayyan | Cartoon Network Racing (Nintendo DS) | Geoduck |