Break And Continue

Break

The break statement stops the loop immediately. Code in the loop body following the break statement is not executed. Break stops the loop over if the result of the conditional expression in your loop is true.

Example :

   for(var i:int=1; i<23; i+=4){
      if(i==13){
        break;
      }
      trace(i);
   } //output 1 5 9


Continue

The continues statement pauses the execution of the loop body, applies the loop's update, and the restarts the code in the loop body. The code below shows continue being used to skip an iteration of the loop.

     for(var i:int=1; i<23; i+=4){
       if(i==13){
          continue;
       }
       trace(i);
     }
     //output 1 5 9 17 21

Using break and continue gives you more precise control over your loops.


Share this

Related Posts

Previous
Next Post »