Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!chaph.usc.edu!alcor.usc.edu!jeenglis From: jeenglis@alcor.usc.edu (Joe English Muffin) Newsgroups: comp.lang.c Subject: Re: The Sins of K&R (break n) Keywords: break, switch, loops, number Message-ID: <12288@chaph.usc.edu> Date: 2 Oct 90 02:32:48 GMT References: <31604@nigel.ee.udel.edu> <12180@crdgw1.crd.ge.com> <2487@lectroid.sw.stratus.com> <4b0hPyW00Vp8M7qVd1@andrew.cmu.edu> <12252@crdgw1.crd.ge.com> <901@gtenmc.UUCP> Sender: news@chaph.usc.edu Followup-To: alt.cfutures Organization: Joe's Homeopathic Hangover Remedies Lines: 42 Nntp-Posting-Host: alcor.usc.edu ravim@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@alcor.usc.edu