Main menu puzzle, Klaus

Stephen Barncard stephenREVOLUTION at barncard.com
Sun Feb 19 05:06:28 EST 2006


and this isn't cleaner? LOOK - a whole bunch of if's and thens don't 
have to be repeated over and over.

on menupick varMenuItemSelected
  SWITCH varMenuItemSelected
  CASE "Cut"
    SubCut
  break
  CASE "Copy"
    SubCopy
  break
  CASE "Paste"
    SubPaste
  break
  CASE "Undo"
    SubUndo
  break
  CASE "Word Wrap"
    SubWordWrap
  break
  DEFAULT
    --
  END SWITCH
end menupick


I find SWITCH/CASE statements to be quite elegant, actually, and you 
can do things in fewer lines than an IF statement  will do in many 
situations. Execution goes straight down, and breaks are the stoppers!

SWITCH colors
   CASE "green"
   CASE "blue"
   CASE "yellow"
   CASE "orange"
     put "color set one"
   break
   CASE "brown"
   CASE "red"
   CASE "purple"
     put "color set two"
   break
   DEFAULT
     put "not from either set"
END SWITCH

looks pretty linear to me... a lot easier than repetitive ORs or a 
lot of if-thens.

sqb



>And I think another thing, a bit odd I'm sure, but I find the Case 
>statements to be... well... Ugly for some reason.  Just looking at 
>code for a Case statement doesn't seem to flow naturally in my mind, 
>but an equivalent If statement does.  Don't ask me why!  Could be 
>that I'm just a seriously odd fellow ;-)
>
>-Garrett
>P.S. BOYCOTT CASE STATEMENTS!  IF STATEMENTS ROCK!

-- 
stephen barncard
s a n  f r a n c i s c o
- - -  - - - - - - - - -



More information about the use-livecode mailing list