JavaScript Break 语句
如果使用break语句,它会中断所有if...else...if else语句和所有循环吗?如果是这样,你怎么能只打破一个 if/循环呢?
while(test here){if({break;}don't break;)}
If you use the break statement will it break all if...else...if else statements and all loops? If so how can you break just a single if/loop.
while(test here){if({break;}don't break;)}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
break
语句只会跳出您放入它的一个循环。它不会影响 if/else 语句。如果您想打破外部循环,可以使用标签,如此答案中所示。The
break
statement will only break out of the one loop in that you put it in. It doesn't affect if/else statements. If you want to break an outer loop you can use labels, as in this answer.Break 语句将中断循环并继续执行循环后面的代码(如果有)。
检查:http://www.w3schools.com/js/js_break.asp
The break statement will break the loop and continue executing the code that follows after the loop (if any).
Check: http://www.w3schools.com/js/js_break.asp
break;
将跳转到包含for
、do
、while
或switch< 的最深处的末尾/代码> 声明。
break label;
将跳转到带标签的末尾。if
并不重要。break
为不存在的标签,或者相关的for
、do
、while
、或switch
位于不同的函数体中。break;
will jump to the end of the deepest containingfor
,do
,while
orswitch
statement.break label;
will jump to the end of the labelled one.if
doesn't matter.It's an error to
break
to a non-existant label, or if the relevantfor
,do
,while
, orswitch
is in a different function body.我认为 if 语句没有中断。您必须重组 if 语句以仅执行您需要的代码。
然而,有一个
continue;
跳到循环的下一个迭代,而break;
则完全退出循环。I don't think there is a break for if statements. You'll have to restructure your if statement to only execute the code you need.
There is, however, a
continue;
which skips to the next iteration of the loop, whilebreak;
quits the loop entirely.