It was thus said that the Great willisjo at
zianet.com once stated:
When I took C programming in high school, our teacher taught us how to use
goto, but if he saw it in our code, we had 30 seconds to justify it to his
satisfaction before he'd throw the eraser at us. He was a good shot, too ;)
I've been programming in C since 1990, and in that time, I've only used
GOTOs under three conditions (as far as I can remember):
1. A function with a lot of cleanup required if it fails, so I use a
GOTO to clean up before returning an error; this is rare for me
though.
2. State machines. It keeps me sane. This is my biggest use of
GOTOs. My HTML parser has 22 GOTOs (22 states) and without the use
of GOTOs, the code would probably be more of a mess than it already
is.
3. *VERY* rarely, as a mechanism for exceptions, and then, I use
setjmp()/longjmp() (which are non-local GOTOs in C). I think I
played around with this a few times, but gave up on it (I don't
particularly care for the semantics of setjmp() and it has some
rather nasty restrictions on the return value).
-spc (I do tend though, to use multiple returns in a function ... )