Flash / Flex / ActionScript/Statement/continue

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

continue ceases to execute the current iteration of the loop and skips ahead to the next iteration.

   <source lang="java">

package{

 import flash.display.Sprite;
 
 public class Main extends Sprite{
   public function Main(){
       var needle:int = 3;
       var haystack: Array = new Array(1,2,3,4,5,6);
       for (var i:int = 0; i < haystack.length; i++) {
          if (!(hay == haystack[i])) { 
            continue; 
          }
          trace("I found the needle!");
          break;
       }
   }
 }

}

       </source>
   
  


Use continue to avoid dividing by 0

   <source lang="java">

package{

 import flash.display.Sprite;
 
 public class Main extends Sprite{
   public function Main(){
       for (var i:Number = -10; i < 10; i++){
         if (i == 0){
           continue;
         }
         trace(100/i);
       }
   }
 }

} -10 -11.11111111111111 -12.5 -14.285714285714286 -16.666666666666668 -20 -25 -33.333333333333336 -50 -100 100 50 33.333333333333336 25 20 16.666666666666668 14.285714285714286 12.5 11.11111111111111

       </source>