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