javascript 意外的“继续”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6071762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unexpected 'continue'
提问by asifg
I have:
我有:
while (i < l) {
if (one === two) { continue; }
i++;
}
But JSLint says:
但是 JSLint 说:
Problem at line 1 character 20: Unexpected 'continue'.
if (one === two) { continue; }
第 1 行字符 20 出现问题:意外的“继续”。
if (one === two) { continue; }
What mistake did I make? How should my code reallylook?
我犯了什么错误?应该如何我的代码真的看?
回答by Quentin
From the JSLint docs:
来自JSLint 文档:
continue
StatementAvoid use of the continue statement. It tends to obscure the control flow of the function.
continue
陈述避免使用 continue 语句。它往往会模糊函数的控制流。
So take it out entirely if you want to conform to the conventions that JSLint follows.
因此,如果您想遵守 JSLint 遵循的约定,请将其完全删除。
回答by Roy Arisse
What JSLint actually tries to say is to invert the if so you can eliminate the continue:
JSLint 实际上试图说的是反转 if 以便您可以消除 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.
此外,如果您想遵守 JSLint 的严格指南,请不要使用“i++”,而应使用“i+=1”。
Hope this helps :)
希望这可以帮助 :)