Author : Brian Kernighan
Page : << Previous 12
to. But most of the time goto's
aren't needed. (How many have we used up to this point?)
The code can almost always be more clearly expressed by
for/while, if/else, and compound statements.
One use of goto's with some legitimacy is in a program
which contains a long loop, where a while(1) would be too
extended. Then you might write
mainloop:
...
goto mainloop;
Another use is to implement a break out of more than one
level of for or while. goto's can only branch to labels
within the same function.
I am indebted to a veritable host of readers who made
valuable criticisms on several drafts of this tutorial.
They ranged in experience from complete beginners through
several implementors of C compilers to the C language
designer himself. Needless to say, this is a wide enough
spectrum of opinion that no one is satisfied (including me);
comments and suggestions are still welcome, so that some
future version might be improved.
References
C is an extension of B, which was designed by D. M.
Ritchie and K. L. Thompson [4]. The C language design and
UNIX implementation are the work of D. M. Ritchie. The GCOS
version was begun by A. Snyder and B. A. Barres, and com-
pleted by S. C. Johnson and M. E. Lesk. The IBM version is
primarily due to T. G. Peterson, with the assistance of M.
E. Lesk.
[1] D. M. Ritchie, C Reference Manual. Bell Labs, Jan.
1974.
[2] M. E. Lesk & B. A. Barres, The GCOS C Library.
Bell Labs, Jan. 1974.
[3] D. M. Ritchie & K. Thompson, UNIX Programmer's
Manual. 5th Edition, Bell Labs, 1974.
[4] S. C. Johnson & B. W. Kernighan, The Programming
Language B. Computer Science Technical Report 8,
Bell Labs, 1972.
Page : << Previous 12