Livecode Wiki
Advertisement

Switch is the best way to evaluate what to do in case multiple of multiple options. You can also declare a default action in case the other one are not matched. Let see the first example:

put 32 into myVar
switch myVar
  case 32
     answer "myVar is 32"
  break
  case 31
     answer "myVar is 31"
  break
end switch

Note the break keyword, it's mandatory to close the case option, if you don't use it, switch will execute all commands until intercepts a break or the end. Let's another example:

switch myVar
  case 32
  case 31
     answer "myVar is 31 or 32"
  break
end switch

Now let's see to add a default action:

 switch myVar
  case 32
     answer "myVar is 32"
  break
  case 31
     answer "myVar is 31"
  break
  default
     answer "myVar isn't 31, nor 32. I don't know what is... :-(" 
end switch
Advertisement