Is an argument to break, continue a bad idea?
Henry Spencer
henry at utzoo.uucp
Sat May 5 02:57:46 AEST 1990
[Puzzled comp.lang.c readers, note that this has moved over from comp.std.c.]
In article <742 at mwtech.UUCP> martin at mwtech.UUCP (Martin Weitzel) writes:
> ..... {
> ..... {
> ..... {
> /*
> Here we are in some complicated nested
> conditions and loops. Suddenly something
> very ugly happens...
Diagnosis: excessively nested control structures. The remedy is to re-read
K&R1 chapter 4 about the most important control structure of all: functions.
In 15 years of active C programming, I don't think I have ever used a goto
in original code. (Once or twice I have used one in maintaining code that
was already full of them, when I didn't have time to redo it.) I attribute
this mostly to a strong distaste for deep nesting. Breaking things up into
functions makes life easier in a lot of ways, not least of them being the
ability to use `return' to get yourself out of messes. Amazingly enough,
when you do this systematically, you find that you seldom have any desire
to use `goto'. It just isn't needed.
>>... When you see "goto", you don't know where it goes without
>>hunting for the label, and you don't know if anything else goes to that
>>label without searching the whole function for more gotos...
>
>Really?
>What is your argument? If you wanted to say that `break' is preferable
>over `goto', you must have a *very* advanced syntax directed editor.
>With a normal editor (like "vi"), I'll have less problems to hunt for
>`goto's (with labels!) than for `break'...
I don't care much for `break' either, although I concede its necessity
in some cases because C lacks higher-level constructs to do certain jobs.
Mind tend to come with comments like `/* NOTE BREAK OUT */' to make them
more conspicuous.
>If you recommend to avoid
>`break' too, then what about the additional flags for breaking
>out of loops. Don't they suffers from the same problems(%)? ...
I recommend composing programs in an orderly way to avoid the need, mostly.
>... IMHO flags often obscure
>things that would be clarified by DISCIPLINED USE OF `goto's.
Yes, it's better to simply avoid both.
--
If OSI is the answer, what is | Henry Spencer at U of Toronto Zoology
the question?? -Rolf Nordhagen| uunet!attcan!utzoo!henry henry at zoo.toronto.edu
More information about the Comp.lang.c
mailing list