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