Fandom

Livecode Wiki

Switch

1,965pages on
this wiki
Add New Page
Comments0 Share

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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.