The D Programming Language: switches

Richard Harter g-rh at cca.CCA.COM
Tue Mar 22 03:54:22 AEST 1988


In article <3074 at haddock.ISC.COM> karl at haddock.ima.isc.com (Karl Heuer) writes:
>In article <941 at micomvax.UUCP> ray at 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.



More information about the Comp.lang.c mailing list