I am getting an error that this has an illegal continue statement. I have a list of words to check for form validation and the problem is it was matching some of the substrings to the reserved words so I created another array of clean words to match. If it matches a clean word continue else if it matches a reserved word alert the user
$.each(resword,function(){ $.each(cleanword,function(){ if ( resword == cleanword ){ continue; } else if ( filterName.toLowerCase().indexOf(this) != -1 ) { console.log("bad word"); filterElem.css('border','2px solid red'); window.alert("You can not include '" + this + "' in your Filter Name"); fail = true; } }); });
The continue statement breaks one iteration (in the loop) if a specified condition occurs, and continues with the next iteration in the loop. The difference between continue and the break statement, is instead of "jumping out" of a loop, the continue statement "jumps over" one iteration in the loop.
No, continue can not be used outside loops.
The continue statement (with or without a label reference) can only be used to skip one loop iteration. The break statement, without a label reference, can only be used to jump out of a loop or a switch.
The continue statement in JavaScript is used to jumps over an iteration of the loop. Unlike the break statement, the continue statement breaks the current iteration and continues the execution of next iteration of the loop. It can be used in for loop, while loop, and do-while loop.
The continue
statement is fine for normal JavaScript loops, but the jQuery each
method requires you to use the return
statement instead. Return anything that's not false and it will behave as a continue
. Return false, and it will behave as a break
:
$.each(cleanword,function(){ if ( resword == cleanword ){ return true; } else if ( filterName.toLowerCase().indexOf(this) != -1 ) { //...your code... } });
For more information, see the jQuery docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With