I have:
while (i < l) { if (one === two) { continue; } i++; }
But JSLint says:
Problem at line 1 character 20: Unexpected 'continue'.
if (one === two) { continue; }
What mistake did I make? How should my code really look?
The continue statement terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration. When used incorrectly it makes code less testable, less readable and less maintainable.
continue with while Loop In a while loop, continue skips the current iteration and control flow of the program jumps back to the while condition. The continue statement works in the same way for while and do... while loops.
The continue statement in C programming works somewhat like the break statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between. For the for loop, continue statement causes the conditional test and increment portions of the loop to execute.
You can't use continue with if (not even a labelled one) because if isn't an iteration statement; from the spec. It is a Syntax Error if this ContinueStatement is not nested, directly or indirectly (but not crossing function boundaries), within an IterationStatement.
From the JSLint docs:
continue
StatementAvoid use of the continue statement. It tends to obscure the control flow of the function.
So take it out entirely if you want to conform to the conventions that JSLint follows.
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