The switch statement is useful when performing the same action for one of several matching possibilities. : switch « Statement « Flash / Flex / ActionScript






The switch statement is useful when performing the same action for one of several matching possibilities.

 


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){


        var animalName:String = "dove";
        
        switch (animalName) {
          case "turtle":
          case "iguana":
            trace("Yay! You named a reptile.");
            break;
          case "dove":
          case "cardinal":
            trace("Sorry, you specified a bird, not a reptile.");
            break;
          default:
            trace("Sorry, try again.");
        }
    }
  }
}

        








Related examples in the same category

1.The general form of a switch statement
2.Working with the switch Statement
3.switch statement executes one of several possible code blocks based on the value of a single test expression
4.Adding a break statement to switch statement
5.Adding a default statement