The general form of a switch statement : switch « Statement « Flash / Flex / ActionScript






The general form of a switch statement

 

switch (testExpression) {
  case caseExpression:
    // case body
  case caseExpression:
    // case body
  default:
    // case body
}


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

        var animalName:String = "dove";
        switch (animalName) {
          case "turtle":
            trace("Yay! 'Turtle' is the correct answer.");
          case "dove":
            trace("Sorry, a dove is a bird, not a reptile.");
          default:
            trace("Sorry, try again.");
        }

    }
  }
}

        








Related examples in the same category

1.Working with the switch Statement
2.switch statement executes one of several possible code blocks based on the value of a single test expression
3.The switch statement is useful when performing the same action for one of several matching possibilities.
4.Adding a break statement to switch statement
5.Adding a default statement