Illegal continue statement?(非法的继续声明?)
问题描述
我有类似下面的代码:
_.each data, (value, type) ->
switch type
when "answered"
icon = "results_answered"
label = definitions.results.metrics.ta
when "leftblank"
icon = "results_lb"
label = definitions.results.metrics.tlb
when "standing"
icon = "results_standing"
label = definitions.results.metrics.cs
when "minimum"
icon = "results_min"
label = definitions.results.metrics.lowest
else
continue
metricLine = utilities.div("metricline")
metricLine.grab utilities.sprite(icon, "metric_icon")
metricLine.grab utilities.div("metriclabel", label + ":")
metricLine.grab utilities.div("metricvalue", value)
metricContainer.grab(metricLine)
metricContainer
但它会向我的浏览器抛出以下错误:
But it throws the following error to my browser:
Uncaught SyntaxError: Illegal continue statement
Uncaught SyntaxError: Illegal continue statement
是否可以像我尝试的那样包含 continue
而不会引发错误?
Is it possible to include a continue
like I am trying without throwing the error?
推荐答案
如果你想继续下一个循环迭代,你想要return
,而不是continue
,如你传递给 each
的是一个函数.
If you want to continue with the next loop iteration, you want return
, not continue
, as what you're passing to each
is a function.
在您提到熟悉 C# foreach
循环的评论中,因此想要使用 continue
.不同之处在于,使用 C# 的 foreach
,您处理的是一个实际的循环构造,而 each
实际上是为每个循环迭代调用一个函数,所以它不是(在语言级别)一个循环,所以你不能继续
它.
In a comment you mentioned being familiar wih the C# foreach
loop, hence wanting to use continue
. The difference is that wih C#'s foreach
, you're dealing with an actual loop construct, whereas each
is actually calling a function for each loop iteration, so it's not (at a language level) a loop, so you can't continue
it.
这篇关于非法的继续声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:非法的继续声明?


基础教程推荐
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01