Flash / Flex / ActionScript/Statement/break

Материал из Web эксперт
Перейти к: навигация, поиск

Use break statements to exit the switch statement after executing the actions under the matching case.

 
    
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
 
        var animalName:String = "dove";
        
        switch (animalName) {
          case "turtle":
            trace("Yay! "Turtle" .");
            break;
          case "dove":
            trace("Sorry, .");
            break;
          default:
            trace("Sorry, try again.");
        }
    }
  }
}



Using break and continue in Statement Blocks

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var aTitles:Array = ["a", "b", "c"];
        
        for (var i:Number = 0; i < aTitles.length; i++){
          if(aTitles[i] == "a") {
            trace("Title found.");
            break;
          }
        }
    }
  }
}