The D Programming Language: switches
Eddie Wyatt
edw at IUS1.CS.CMU.EDU
Tue Mar 22 06:40:44 AEST 1988
>>
>>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. :-)]
I think he meant in terms of expressability. Which is true in a
practical sense, false in theorectically. 'switch' and 'else-if'
are equivalent in terms of expressability.
--
Eddie Wyatt e-mail: edw at ius1.cs.cmu.edu
More information about the Comp.lang.c
mailing list