Path: utzoo!mnetor!uunet!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.lang.c Subject: Re: The D Programming Language: switches Message-ID: <25835@cca.CCA.COM> Date: 21 Mar 88 17:54:22 GMT References: <222965b9@ralf.home> <941@micomvax.UUCP> <3074@haddock.ISC.COM> Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge, MA Lines: 17 In article <3074@haddock.ISC.COM> karl@haddock.ima.isc.com (Karl Heuer) writes: >In article <941@micomvax.UUCP> ray@micomvax.UUCP (Ray Dunn) writes: > >Yes, in a sense switch is less powerful than an else-if chain. Let's keep it, >for the same reasons that we retain flow constructs less powerful than goto. > Theoretically the switch construct is more powerful than an else-if chain because it selects in one step. Execution is O(1) rather than O(n) where n is the number of branches. It is, for example, considerably more efficient to use a switch with a thousand cases than an else-if chain with a thousand elses. [This is not to be taken as an endorsement of such code. :-)] -- In the fields of Hell where the grass grows high Are the graves of dreams allowed to die. Richard Harter, SMDS Inc.