Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!decwrl!glacier!oliveb!felix!scgvaxd!trwrb!desint!geoff From: geoff@desint.UUCP (Geoff Kuenning) Newsgroups: net.lang.c Subject: Re: An amusing piece of code Message-ID: <195@desint.UUCP> Date: Sat, 5-Apr-86 16:00:12 EST Article-I.D.: desint.195 Posted: Sat Apr 5 16:00:12 1986 Date-Received: Fri, 11-Apr-86 20:32:07 EST References: <1370@ism780c.UUCP> Reply-To: geoff@desint.UUCP (Geoff Kuenning) Organization: SAH Consulting, Manhattan Beach, CA Lines: 97 In article <1370@ism780c.UUCP> tim@ism780c.UUCP (Tim Smith) writes: > 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; > [followed by code that makes me puke] (1) switch (thing) { case A: A-code; break; case B: B-code; BCD-common-code (); break; case C: C-code; BCD-common-code (); break; case D: D-code; BCD-common-code (); break; case E: E-code; break; } (2) switch (thing) { case A: A-code; break; case B: case C: case D: switch (thing) { case B: B-code; break; case C: C-code; break; case D: C-code; break; } BCD-common-code (); break; case E: E-code; break; } (3) switch (thing) { case A: A-code; break; case B: B-code; goto common; case C: C-code; goto common; case D: D-code; common: BCD-common-code; break; case E: E-code; break; } Moral: don't be so rabid about avoiding goto's that you wind up with something even uglier. It makes you look foolish. -- Geoff Kuenning {hplabs,ihnp4}!trwrb!desint!geoff