Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site ism780c.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!hplabs!sdcrdcf!ism780c!tim From: tim@ism780c.UUCP (Tim Smith) Newsgroups: net.lang.c Subject: An amusing piece of code Message-ID: <1370@ism780c.UUCP> Date: Fri, 4-Apr-86 23:10:07 EST Article-I.D.: ism780c.1370 Posted: Fri Apr 4 23:10:07 1986 Date-Received: Tue, 8-Apr-86 04:48:06 EST Reply-To: tim@ism780c.UUCP (Tim Smith) Organization: Interactive Systems Corp., Santa Monica, CA Lines: 42 Here is an amusing piece of code that someone who wants to remain annonymous invented. The situation is that we have something that, if written with if-then-else would be if ( thing == A ) A-code; else if ( thing == B || thing == C || thing == D ) { switch ( thing ) { case B: B-code; break; case C: C-code; break; case D: D-code; break; } BCD-common-code; } else if ( thing == E ) E-code; A, B, C, D, and E are constant expressions, so this is not elegant. We would like to use a switch for everything. Here is a solution: switch ( thing ) { case A: A-code; break; case B: B-code; if ( 0 ) { case C: C-code; if ( 0 ) { case D: D-code; }} BCD-common-code; break; case E: E-code; } Noone here has been able to come up with a reasonable style for this. The example above is not to bad, but if B-code, C-code, etc, are complicated, then it starts to get ugly. -- Tim Smith sdcrdcf!ism780c!tim || ima!ism780!tim || ihnp4!cithep!tim PS: I bet you were relieved that I didn't say you invented this, right Darryl?