Main menu puzzle, Klaus

J. Landman Gay jacque at hyperactivesw.com
Sat Feb 18 17:56:32 EST 2006


Garrett Hylltun wrote:

> And to this day, I just don't understand the whole purpose of the  Case 
> statement.....  Still don't even after reading a few of the  replies to 
> this thread.

I prefer switch/case statements when there are many options a script has 
to deal with. I'll admit though that there is little difference between 
switch/case and if/then constructs when the choices are straightforward.

There is an advantage to using switch statements though when several 
options need to result in the same behavior. For example:

if tColor = "red" or tColor = "blue" or tColor = "purple" or tColor = 
"green" then
   doColorThing
else if tColor = "black" or tColor = "white" then
   doB&WThing
end if

Sometimes these constructs can get very complicated, at least visually. 
A switch/case statement "falls through" to the next line unless it hits 
a "break", so the above can be represented instead like this:

case "red"
case "blue"
case "purple"
case "green"
   doColorThing
   break
case "black"
case "white"
   doB&WThing
   break
...

The above construction is easier for me to read and executes faster in a 
script.


-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list