break, continue, return, goto

Mike Shannon mikes at 3comvax.UUCP
Tue Nov 5 09:07:22 AEST 1985


In the cited article, Michael Baldwin write
> This is in response to those who think that break, continue, and
> multiple returns are bad things.  As with anything, they can be
> abused, but I find continue and multiple returns extremely useful
> for dealing with errors, and break for ending complicated search loops.
>.......

	And I think he has really addressed the critical issue.  The important
thing is that the code we write clearly show our intention.  If you 
*think* about a problem in a certain way, your code should reflect it.
This link between syntax and intention makes programs more reliable,
easier to read, and cheaper to maintain.
	If your code looks 'goto'-ey, you probably should attack your
programming problem from a different perspective.  Think about the
problem in a new way.
	I think that multiple return and break statements are fine to deal
with unexpected error conditions.  In this context, boolean loop-termination
variables might obscure the author's intention.
	But when the programmer has a complete choice of data structures
and program structure, it's another story.  All too often, multiple
returns and break statements reflect either a lack of exposure to data
structures or fuzzy thinking about the problem which needs to be solved.
-- 
			Michael Shannon {ihnp4,hplabs}!oliveb!3comvax!mikes



More information about the Comp.lang.c mailing list