Breaking out of several nested loops
Henry Spencer
henry at utzoo.UUCP
Sun Oct 14 08:55:24 AEST 1984
> ...and the parent article suggests ripping this nest out into a separate
> procedure which has, as parameters, all of the variables needed in the nest
> of control constructs--this allows replacing the "goto" with a "return".
> I guess the trailing-line-eater bug got the parent article, 'cause there
> wasn't a ":-)" at the end.
>
> I'm sure glad to see that someone would violate all concepts of modularity
> (yanking part of the innards out of a procedure), clean interface (defining
> a new procedure without regard to how many parameters might be needed),
> and, dare I say the word, efficiency. ...
Gee, I've always found that modularity and clean interface were *improved*
by breaking the innards out into a separate function any time they start
getting non-trivial. As an accidental side effect of this, "return" then
suffices for multi-level exits. And it's never produced any efficiency
problems in my stuff. Efficiency is the standard excuse for ugliness,
and that's usually all it is: an excuse.
Note that I am not suggesting that you can retrofit this approach into
existing code without rethinking said code to make it clean and modular.
--
Henry Spencer @ U of Toronto Zoology
{allegra,ihnp4,linus,decvax}!utzoo!henry
More information about the Comp.lang.c
mailing list