文档介绍:Structured Programming with go to Statements
DONALD E. KNUTH
Stanford University, Stanford, California 9~S05
A consideration of several different examples sheds new light on the problem of ereat-
ing reliable, well-structured programs that behave efficiently. This study focuses
largely on two issues: (a) improved syntax for iterations and error exits, making it
possible to write a larger class of programs clearly and efficiently without go to state-
ments; (b) a methodology of program design, beginning with readable and correct,
but possibly inefficient programs that are systematically transformed if necessary into
efficient and correct, but possibly less readable code. The discussion brings out op-
posing points of view about whether or not go to statements should be abolished;
some merit is found on both sides of this question. Fina!ly, an attempt is made to
define the true nature of structured programming, and to mend fruitful direc-
tions for further study.
Keywords and phrases: structured programming, go to statements, language design,
event indicators, recursion, Boolean variables, iteration, optimization of programs,
program transformations, program manipulation systems searching, Quieksort,
efficiency
CR categories: , , , , , (, , , )
You may go when you will go,
And I will stay behind.
--Edna St. Vincent Millay [66]
Most likely you go your way and I'll go mine.
--Song title by Bob Dylan [33]
Do you suffer from painful elimination?
--Advertisement, J. B. Williams Co.
INTRODUCTION change your life. The reasons for this revolu-
tion and its future prospects have been aptly
A revolution is taking place in the way we described by E. W. Dijkstra in his 1972 Tur-
write programs and teach programming, be-
ing Award Lecture, "The Humble Program-
cause we are beginning to understand the
mer" [27l.
associated mental processes more deeply.