-2

I have a two for loops checking two sets of items. I have the following code:

for(var key in powder){
    for(var key2 in powder){
        if(key == key2){ continue; };
        [...]
    }
    [...]
}

([...]s are unimportant info.)

But, javascript gives me an error: Uncaught SyntaxError: Illegal continue statement

And I cannot figure out why! I have checked multiple resources(W3Schools, stackoverflow, ect.) and it did not have anything. Please help!

Fuzzyzilla
  • 356
  • 4
  • 15

1 Answers1

1

Tried similar code in js and works fine. May be some problem with lines of code which you didn't post or some problem with your powder variable

<html>

<script>

 function fun(){
    var powder =[1,2,4,5];
   for(var key in powder){
     for(var key2 in powder){
     if(key == key2){ alert("con");continue; };
    }
}

}
  </script>

     <body onload="fun()"></body>
 </html>

The following code will result in illegal continue statement.The continue statement must be present in the loop not in the called function.

 <html>

 <script>
      function funOne(){
  for(var i=0;i<10;i++){
  fun();
 }
  }
   function fun(){
    if(1==1){ //this line is the cause of error
     continue;
   }
   var powder =[1,2,4,5];
    for(var key in powder){
     for(var key2 in powder){
     if(key == key2){ alert("con");continue; };
   }
}

}
  </script>

   <body onload="funOne()"></body>
 </html>
KDP
  • 1,481
  • 7
  • 13