Path: utzoo!mnetor!uunet!husc6!bbn!rochester!PT.CS.CMU.EDU!IUS1.CS.CMU.EDU!edw From: edw@IUS1.CS.CMU.EDU (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: The D Programming Language: switches Message-ID: <1186@PT.CS.CMU.EDU> Date: 21 Mar 88 20:40:44 GMT References: <222965b9@ralf.home> <941@micomvax.UUCP> <3074@haddock.ISC.COM> <25835@cca.CCA.COM> Sender: netnews@PT.CS.CMU.EDU Organization: Carnegie-Mellon University, CS/RI Lines: 20 >> >>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@ius1.cs.cmu.edu