为什么这个标记为 javaScript continue 不起作用?
我使用这段代码来应对一些圆圈重叠:
iCantThinkOfAGoodLabelName:
x = genX(radius);
y = genY(radius);
for(i in circles) {
var thisCircle = circles[i];
if(Math.abs(x-thisCircle["x"])+Math.abs(y-thisCircle["y"])>radius*2) { //No overlap
continue;
} else { //Overlap
continue iCantThinkOfAGoodLabelName; //<- Line 256
}
thisCircle = [];
}
但是当到达 continue 语句时,chrome 的开发者控制台给我这个: client.html:256 Uncaught SyntaxError: Undefined label 'iCantThinkOfAGoodLabelName'
I am using this code to weather some circles are overlapping:
iCantThinkOfAGoodLabelName:
x = genX(radius);
y = genY(radius);
for(i in circles) {
var thisCircle = circles[i];
if(Math.abs(x-thisCircle["x"])+Math.abs(y-thisCircle["y"])>radius*2) { //No overlap
continue;
} else { //Overlap
continue iCantThinkOfAGoodLabelName; //<- Line 256
}
thisCircle = [];
}
But when the continue statement is reached, chrome's developer console gives me this: client.html:256 Uncaught SyntaxError: Undefined label 'iCantThinkOfAGoodLabelName'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
标签应该紧接在循环之前
The label should come immediately before the loop
因为
iCantThinkOfAGoodLabelName:
需要位于循环之前。我认为你想要的是一个功能..
Because
iCantThinkOfAGoodLabelName:
needs to be right before the loop.I think what you want is a function..
标签名称和关联循环之间不应有任何语句。
修复它。
There should not be any statement between a label name and associated loop.
fixes it.
我最近遇到了这个问题,我通过在 Node.js 版本
v0.8.x
的循环标签中使用全小写来解决它。使用
labelname:
与iCantThinkOfAGoodLabelName:
可能会对您有所帮助。其他人已经正确纠正了您标签的位置。它应该紧接在
for
循环之前。标签上的 Mozilla 开发者网络 建议避免使用标签,而更喜欢调用函数或抛出错误。如果可能的话,您可能会重新考虑使用它们的策略。
根据结果调用函数的示例:
I recently had this issue and I resolved it by using all lowercase in the loop's label in version
v0.8.x
of Node.js.Using
labelname:
vs.iCantThinkOfAGoodLabelName:
might help you.Others have correctly corrected you on the location of the label. It should be immediately before the
for
loop.The Mozilla Developer Network on labels advises to avoid using labels, and instead prefer calling functions or throwing an error. You might rethink your strategy on using them, if possible.
Example of calling a function depending on result: