开发者

Unexpected 'continue'

开发者 https://www.devze.com 2023-03-07 01:57 出处:网络
I have: while (i < l) { if (one === two) { continue; } i++; } But JSLint says: Problem at line 1 char开发者_如何学Pythonacter 20: Unexpected \'continue\'.

I have:

while (i < l) {
   if (one === two) { continue; }
   i++;
}

But JSLint says:

Problem at line 1 char开发者_如何学Pythonacter 20: Unexpected 'continue'.

if (one === two) { continue; }

What mistake did I make? How should my code really look?


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.


What JSLint actually tries to say is to invert the if so you can eliminate the continue:

while (i < 1) {
    if (one !== two) {
        i += 1;
    }
}

Furthermore, don't use "i++", but use "i+=1", if you want to stick to the strict guides of JSLint.

Hope this helps :)

0

精彩评论

暂无评论...
验证码 换一张
取 消