Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!brl-adm!brl-smoke!smoke!LINNDR%VUENGVAX.BITNET@wiscvm.ARPA From: LINNDR%VUENGVAX.BITNET@wiscvm.ARPA Newsgroups: net.lang.c Subject: An amusing piece of code Message-ID: <2424@brl-smoke.ARPA> Date: Sun, 6-Apr-86 14:52:24 EST Article-I.D.: brl-smok.2424 Posted: Sun Apr 6 14:52:24 1986 Date-Received: Wed, 9-Apr-86 22:19:23 EST Sender: news@brl-smoke.ARPA Lines: 41 In posting<1370@ism780c.UUCP>, Tim Smith asks about a switch with common code for some cases. I have seen two solutions. 1) put the common code in a subroutine 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) use the much abused goto statment switch(thing) { case A: A-code; break; case B: B-code; goto BCD_common; case C: C-code; goto BCD_common; case D: D-code; BCD_common: BCD-common-code; break; case E: E-code; break; } Hope one of these helps you. David Linn ---------------------------------------------------------- BITNET: LINNDR@VUEngVAX.BITNET or PEARL@VANDVMS1.BITNET MAILNET: LINN_D_R \ David_R_Linn >@VANDERBILT.MAILNET David_Linn / CSNET: drl@vanderbilt.csnet SnailMail: P.O. 3241-B Vanderbilt Nashville, TN 37235