The Sins of K&R (break n)
Joe English Muffin
jeenglis at alcor.usc.edu
Tue Oct 2 12:32:48 AEST 1990
ravim at gtenmc.UUCP (Ravi K Mandava ( Vox Populi )) writes:
>To solve the original problem (or sin, whatever) (i.e. to be able to break
>out of a switch statement within a 'for' or 'while' loop), why not change
>the 'break' statement to take an argument (like the 'return' statement does)
>that denotes the number of loops (including switch body) that you would
>like to get out of?
Or, you could just use a (GASP!) goto.
'break n;' means the reader has to count
the enclosing loops; this would probably
be painful for n >= 3 or so. Under the
assumption that a symbolic name is better
than a number, a well-placed goto is
probably "more structured" than a multi-level
break.
>IMHO, this has some advantages like
> (a) you can still use the old syntax (like having to use 'break'
> in each 'case' body thus allowing 'fall through' wherever it
> is useful and having the ability to break out of the innermost
> 'for' or 'while' loop)
Ditto goto.
> (b) you can break out of any number of loops thus eliminating
> the need of using flags
Ditto goto.
>The same syntax can be extented to the 'continue' statement as well.
Hmm... Has anyone started a "Frequently Proposed
Ways to Futz With C" list? Preferably with a
list of reasons why it shouldn't be changed?
--Joe English
jeenglis at alcor.usc.edu
More information about the Comp.lang.c
mailing list