Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!apple!jdevoto From: jdevoto@Apple.COM (Jeanne A. E. DeVoto) Newsgroups: comp.sys.mac.hypercard Subject: Re: Why no 'case' statement in Hypertalk? Suggestions? Message-ID: <53699@apple.Apple.COM> Date: 6 Jun 91 05:26:39 GMT References: <1991Jun4.234844.1280@cognet.ucla.edu> Organization: Apple Computer Inc., Cupertino, CA Lines: 67 In article <1991Jun4.234844.1280@cognet.ucla.edu> earl@cogdev.cognet.ucla.edu (Earl Williams) writes: >Is there really no 'case' statement in Hypertalk, or am I missing its >equivalent? For simple keypress trapping, I'd like to do something like >the following: > >on keyDown key > case > key = 'a' then do this else > key = 'b' then do that else > key = 'c' then do the other > end >end keyDown > >Instead, I have to use standard if-then-else statements which, when >formatted, give the false impression that I'm doing nesting. > >on keyDown key > if key = 'a' then do this else > if key = 'b' then do that else > if key = 'c' then do the other > end if > end if > end if >end keyDown > >This is extremely inelegant, if not confusing (when used in a more >complex example than this, of course. Write your conditional like this: if key is "a" then do this else if key is "b" then do that else if key is "c" then do the other Or, if your statements are more than one line (even if they're not, if you're a neatness freak or want complete clarity when using nested ifs): if key is "a" then do this else if key is "b" then do that else if key is "c" then do the other end if You can embellish this with an exception case at the end: if key is "a" then do this else if key is "b" then do that else if key is "c" then do the other else do something else end if Just one end if, at the end, and no Vogage to the Righthand Edge of the Script Editor. -- ========= jeanne a. e. devoto ======================================== jdevoto@apple.com | You may not distribute this article under a jdevoto@well.sf.ca.us | compilation copyright without my permission. ______________________________________________________________________ Apple Computer and I are not authorized | CI$: 72411,165 to speak for each other. |