Path: utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!pacbell!ames!mailrus!tut.cis.ohio-state.edu!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.lang.c Subject: Re: The D Programming Language: cases Message-ID: <25395@cca.CCA.COM> Date: 8 Mar 88 22:40:41 GMT References: <222965b9@ralf.home> <2403@umd5.umd.edu> <25200@cca.CCA.COM> <562@acf3.NYU.EDU> <2928@haddock.ISC.COM> Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge, MA Lines: 34 > >Of course, even C-like fallthrough isn't good enough if you have THREE cases >that end up at the same point. (Assuming the code to be executed is AC | BC | >C, not ABC | BC | C.) Or even two cases with different initial segments (AC | >BC). Might just as well use the same construct (goto) for all of these. (But >I do like `goto case X` and `goto default`; one ought to be able to use the >existing label.) A more general solution runs as follows: Associate a flag with each such block.Set the execution control flags in the switch case blocks; execute the blocks under if control. E.g. ex_A = ex_B = ex_C = 0; switch (foo) { case 0: ex_A = ex_C = 1; break; case 1: ex_B = ex_C = 1; break; case 2: ex_C = 1; break; default: break; } if (ex_A) {A} if (ex_B) {B} if (ex_C) {C} This works quite nicely if the blocks are to be sequentially executed. In the general case more than one block may be executed per case, in varying orders, and the order is affected by results within blocks, I would much rather use state machine logic and transition tables than a rats nest of goto's. This is a personal taste, no doubt, but I find it is easier to construct and maintain the tables, then it is to go into the code and fiddle with the logic. -- In the fields of Hell where the grass grows high Are the graves of dreams allowed to die. Richard Harter, SMDS Inc.