Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of break and continue in jQuery

I know with core Javascript we can do things like this:

for(i=1;i<10;i++){
   if(i==5){
    //break or continue
   }
}

But why this is not correct ?

$.each(iteratorarray,function(i){ //iteratorarray - just an array
  if(i==5){
    //break or continue,will cause error here
  }
});
like image 434
coolguy Avatar asked Jan 10 '13 05:01

coolguy


1 Answers

This behavior is what is implemented by jQuery. This is what jQuery api document say "We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration", You can read about it here.

like image 192
Adil Avatar answered Sep 30 '22 20:09

Adil