Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!caen!umich!wsu-cs!cms.cc.wayne.edu!EIVERSO From: EIVERSO@cms.cc.wayne.edu Newsgroups: comp.sys.mac.hypercard Subject: Re: Better Re: Why no case statement in HyperTalk? Message-ID: <1991Jun17.134505.21333@cs.wayne.edu> Date: 17 Jun 91 13:45:05 GMT Sender: News@cs.wayne.edu Organization: Wayne State University Lines: 45 psych@watserv1.waterloo.edu (R. Crispin - Psychology) writes >In article <1991Jun14.175048.20051@cs.wayne.edu> EIVERSO@cms.cc.wayne.edu write >>I'd write it like this: >> >>on keyDown >> if key = "a" then doThis >> if key = "b" then doThat >> if key = "c" then doTheOther >>end keyDown >> >This is a slower technique since no matter what value KEY has all 3 statements >are executed. The only time this is faster is if key is unassigned. A >better technique is as follows >on keyDown Key > if key = "a" then doThis > else if key = "b" then doThat > else if key = "c" then doTheOTher >end keydown >I ran some tests and this can be up to 25% faster but usually it is 10% faster If I don't talk may way out of this one, well... All three statements would not necessarily be executed. It depends on the handlers messaged in the KeyDown handler. For instance: on doThis exit to HyperCard --no further processing! end doThis Since some of you might think this os a cop-out here's a MUCH BETTER script on keyDown Key --check to see if the key pressed has a handler (either a, b, or c has one) if key is in "abc" then do "keyProc" & key --calls handlers keyProca, keyProcb, or keyProcc end keyDown Hopefully the elegance of this code will save my good name. --Eric Iverson