Breaking out of several nested loops (& ANSI C)

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Wed Oct 17 10:01:13 AEST 1984


The "break looplabel;" and "continue looplabel;" proposals should
not be added to the C language because they provide no additional
functionality but complicate compilation.

As has been repeatedly pointed out in this debate, they are not any
clearer than similar use of "goto label;".  Part of the spurious
argument to the contrary assumes the silly K & R brace conventions
are being used (sorry, guys, you're still my heroes).  Tell me how

	while ( condition )
	    {
		...
		if ( emergency )
		    goto forward;
		...
	    }
    forward:

is any harder to comprehend than

    backward:
	while ( condition )
	    {
		...
		if ( emergency )
		    break backward;
		...
	    }

Unless the proposal is combined with outlawing "goto", nothing is
gained by it.  However, the ANSI committee better not outlaw "goto"
since a large amount of existing C code, including a few UNIX system
utilities, would be broken by this.  Sure, one could rewrite code
like

    again:
	...
	if ( this_one_not_it )
	    goto again;
	...

to use some other looping mechanism, but the point is not to force
the massive amount of rewriting that this would entail.  Otherwise
non-standard compilers are going to be maintained indefinitely
anyway, which defeats the purpose of trying to outlaw "goto".



More information about the Comp.lang.c mailing list