TerritorioPc


GOTO

:''This page is about the programming command. See Goto for other uses.'' '''GOTO''' is a command found in many programming languages which instructs the computer to jump to another point in the computer program, specified by a label or line number. 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 what are effectively GOTOs. GOTO is found in FORTRAN, Algol programming language|Algol, COBOL, SNOBOL programming language|SNOBOL, BASIC programming language|BASIC, Common Lisp, C programming language|C, C plus plus|C++, D programming language|D, Pascal programming language|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 used in all programming languages. For example, in Java programming language|Java "goto" is a reserved word but does not presently serve any function. In the programming language INTERCAL programming language|INTERCAL, which is a parody of languages like BASIC, Come from|COME FROM is used instead of GOTO. Unlike a function (programming)|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, many computer scientists came to the conclusion that programs should always use the structured flow commands (program loop|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 breaking out of nested loops and exception handling. Another criticism of using GOTO is that it can easily lead to an infinite loop. For example, the following code in BASIC will endlessly output "Hello, world!". 10 PRINT "Hello, world!" 20 GOTO 10 One famous criticism of GOTO is a 1968 letter by Edsger Dijkstra called ''Go To Statement Considered Harmful'' (see external links). 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 go to Statements'' (see external links) 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. Another solution to this problem is writing the desired control structure as a macro (one can do this in almost all Lisp programming language|Lisp dialects and in Forth programming language|Forth). There have been several variations on the GOTO statement. In BASIC, the ''ON GOTO'' statement selects from a list of different places to jump. It can be thought of as a primitive "switch" statement. The ''computed GOTO'' found in Fortran and some BASICs causes a jump to a line number computed by an arithmetic expression. Computed GOTO is often avoided even by programmers who use GOTO, since it makes code even more difficult to read: to determine even the possible destinations of the jump requires evaluating the arithmetic expression that controls it.

See also

  • Jump instruction
  • Control structure#Goto
  • Structured programming
  • Functional programming
  • Navigational database
  • Macro

    References

  • Edsger Dijkstra|Dijkstra, Edsger: http://www.acm.org/classics/oct95/ ''Communications of the ACM'' '''11''':3 (1968), 147–148.
  • Donald Knuth|Knuth, Donald: http://pplab.snu.ac.kr/courses/adv_pl04/papers/p261-knuth.pdf ''Computing Surveys'' '''6''':4 (1974), 261–301.

    External links

  • http://www.geek-central.gen.nz/peeves/programming_discipline.html


  • territoriopc.com // página bajo licencia GNU obtenida de wikipedia