Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  159] [ 2]  / answers: 1 / hits: 21019  / 13 Years ago, wed, may 4, 2011, 12:00:00

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?


More From » loops

 Answers
59

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.



[#92407] Tuesday, May 3, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminuniquer

Total Points: 63
Total Questions: 121
Total Answers: 96

Location: Cambodia
Member since Thu, May 21, 2020
4 Years ago
;