Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!pilchuck!dataio!gtenmc!ravim From: ravim@gtenmc.UUCP (Ravi K Mandava ( Vox Populi )) Newsgroups: comp.lang.c Subject: Re: The Sins of K&R (break n) Keywords: break, switch, loops, number Message-ID: <901@gtenmc.UUCP> Date: 2 Oct 90 00:24: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> Reply-To: ravim@gtenmc.UUCP (Ravi Kumar Mandava) Organization: GTE Telecom, Inc. Bothell, WA Lines: 51 In article <12252@crdgw1.crd.ge.com> volpe@underdog.crd.ge.com (Christopher R Volpe) writes: >In article <4b0hPyW00Vp8M7qVd1@andrew.cmu.edu>, jh4o+@andrew.cmu.edu >(Jeffrey T. Hutzelman) writes: >|>volpe@underdog.crd.ge.com (Christopher R Volpe) writes >|> >|>> Ok, how about requiring the programmer to make it explicit when >|>> he/shewants it to fall through, rather than making that the default? >|>> Like so: >|>> >|>>switch(ch) >|>> { >|>> case 'a': >|>> do_a(); >|>> continue; >|>> case 'b': >|>> do_a_or_b(); >|>> } >|> >|>No!!! I LIKE being able to do the following: >[deleted example using continue statement] > >Sorry, I didn't mean to overload that keyword. I should have suggested >a new keyword, although I can't think of a good one right now... > >================== >Chris Volpe How about 'proceed'? 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? (If my memory serves me right, this syntax [ break n - n is no of loops default being 1 ] is implemented in 'sh' and 'ksh' languages.) 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) (b) you can break out of any number of loops thus eliminating the need of using flags The same syntax can be extented to the 'continue' statement as well. - Ravi Mandava