GOTO
Overview To
beginning programmers, GOTO looks like a great way to control program
flow. With one statement, program control can be moved to any line in the
code base. However, many people feel that GOTO is more dangerous than
useful. The same ability to quickly direct program flow can also create
"spaghetti code"--code that is difficult to understand and
maintain. Follow the links below to see what the experts think about the
usefulness of the GOTO command.
General Information Dijkstra
opened a can of worms when he submitted his famous letter, "GOTO
Statement Considered Harmful" to the Communications of the ACM in
1968. You can read the text of this letter on the Web at www.acm.org/classics/oct95.
Steve McConnell discusses the issue in his book, Code Complete
(Microsoft Press, 1993). The Steve McConnell Web site (www.stevemcconnell.com/books.htm)
carries an excerpt from this book. You can learn more about the use of
GOTO in an IEEE Software article called "Keep It Simple" at www.stevemcconnell.com/art.htm.
Additional Links Control
Statements At this page from the Professional Programmer's Guide
to Fortran 77, you can see how the GOTO statement fits into the context of
other program control structures. In general, the GOTO statement is
considered obsolete or deprecated in most programming languages. But as
you can see from the examples here, there are plenty of other ways to
control program execution. This
page includes a definition of GOTO, and an interesting discussion of some
good uses of GOTO.
|