I have always believed you use continue as follows:
var i;
for (i = 0; i < 10; i++) {
if(i%2===0) {
continue;
}
}
Or
var i, myloop;
myloop: for (i = 0; i < 10; i++) {
if(i%2===0) {
continue myloop;
}
}
But when I run these two snippets of code through JSLint, I get the error:
Problem at line 5 character 5: Unexpected 'continue'. continue;
What am I doing wrong? What is the correct usage?
I guess JSLint just hates continue
:
There are almost always better ways of writing statements that more explicitly define what you are attempting to do without resorting to continue. JSLint is all about the good parts, and not about the parts that are acceptable. It forces you to use a higher standard than the one defined.
Douglas says it best in his book:
"The continue statement jumps to the top of the loop. I have never seen a piece of code that was not improved by refactoring it to remove the continue statement."
You must tick "Tolerate continue", Crockford doesn't like it.
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