Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sdd.hp.com!wuarchive!uunet!comp.vuw.ac.nz!canterbury!phys169 From: phys169@csc.canterbury.ac.nz Newsgroups: comp.lang.pascal Subject: Re: CASE vs. IF Message-ID: <1991Jun7.114712.985@csc.canterbury.ac.nz> Date: 7 Jun 91 11:47:12 +1200 References: <27118@adm.brl.mil> Organization: University of Canterbury, Christchurch, New Zealand Lines: 13 In article <27118@adm.brl.mil>, aeba-im-o-e2@berlin-emh1.army.mil ( IM EMAIL ASST SYS ADMIN) writes: > Is there any run-time difference between using case statements or the > equivalent if-thens? ...cases tend to run faster than if-thens... The answer depends on the compiler and often on the number of cases. The Turbo Pascal compiler generates code to try options, in the order given in the case statement. Other compilers might generate a table look-up (which takes a bit of time & memory overhead, but the increase in time as you add to the case statement can be nil). One example I remember was that if you have less than 5 alternatives in Burroughs Algol, it was more efficient to use if-then-elses. As I said, it depends on the compiler, etc. Mark Aitchison, Physics, University of Canterbury, New Zealand.