Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected 'continue'

Tags:

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?

like image 810
asifg Avatar asked May 20 '11 12:05

asifg


People also ask

What is the rule of Continue statement?

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.

How do you continue while loop?

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.

How does continue work?

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.

Can we use continue in if statement?

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.


1 Answers

From the JSLint docs:

continue Statement

Avoid 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.

like image 181
Quentin Avatar answered Oct 03 '22 06:10

Quentin