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.
这篇关于非法的继续声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:非法的继续声明?
基础教程推荐
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 响应更改 div 大小保持纵横比 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 动态更新多个选择框 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01