From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_20,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Xref: utzoo comp.software-eng:3131 comp.lang.ada:3417 comp.lang.c:26733 comp.lang.lisp:2895 comp.lang.misc:4384 comp.lang.modula2:2160 comp.lang.pascal:3204 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!jarthur!elroy.jpl.nasa.gov!forsight!gat From: gat@robotics.Jpl.Nasa.Gov (Erann Gat) Newsgroups: comp.software-eng,comp.lang.ada,comp.lang.c,comp.lang.lisp,comp.lang.misc,comp.lang.modula2,comp.lang.pascal Subject: Re: problems/risks due to programming language, stories requested Summary: A better way to do fallthrough switch Message-ID: <408@forsight.Jpl.Nasa.Gov> Date: 9 Mar 90 16:55:58 GMT References: <1004@micropen> <8218@hubcap.clemson.edu> <2596@gmu90x.gmu.edu> <672@software.software.org> Organization: Jet Propulsion Laboratory, Pasadena, CA List-Id: In article <672@software.software.org>, ciardo@software.org (Gianfranco Ciardo) writes: > Using subroutines is not going to help you make the code shorter, more compact, > or less repetitious (which is not) in a case like this: > > switch (what_to_do) { > case FIVE_THINGS: > ; > case FOUR_THINGS: > ; [etc.] > case ONE_THING: > ; > case NOTHING: > break; > } No, but writing the code like this will: if (what_to_do >= ONE_THING) ; if (what_to_do >= TWO_THINGS) ; if (what_to_do >= THREE_THINGS) ; if (what_to_do >= TWO_THINGS) ; if (what_to_do >= ONE_THING) ; If you wish to quibble over my use of inequalities, replace them with a disjunction of equalities. Erann Gat gat@robotics.jpl.nasa.gov