Newsgroups: comp.sys.mac.hypercard
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!malgudi!caen!umich!wsu-cs!cms.cc.wayne.edu!EIVERSO
From: EIVERSO@cms.cc.wayne.edu
Subject: Re: Why no 'case' statement in Hypertalk?  Suggestions?
Message-ID: <1991Jun14.175048.20051@cs.wayne.edu>
Sender: News@cs.wayne.edu
Organization: Wayne State University
Date: Fri, 14 Jun 91 17:50:48 GMT

 Harry.Myhre@p2.f863.n102.z1.fidonet.org (Harry Myhre) writes

>Earl Williams writes in a message to All on 05 Jun 91

>EW> Is there really no 'case' statement in Hypertalk, or am I missing
>EW> its equivalent?

>You're right, HyperTalk doesn't have a case statement. You could have coded
>your if statement:

>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

>like this instead:

>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 keyDown

>Either way you do it, it's uglier than a nice case statement. And harder to
>read and understand what's going on.

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

Fewer lines, fewer indents, more legible code.
Closer to what you like about a case statement.
I'd save the "else if" for multi line proceedures after an if.
If you want to debate that, be my guest.

A few "nigling" little points...

Double quotes are for containing literal strings, not single quotes.
"Do" and "The" are reserved words.

--Eric
