javascript退出for循环而不返回 [英] javascript exiting for loop without returning

查看:111
本文介绍了javascript退出for循环而不返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我想要退出的for循环:

I have a for loop that I want to exit like this:

function MyFunction() {
  for (var i = 0; i < SomeCondition; i++) {
     if (i === SomeOtherCondition) {
        // Do some work here.
        return false;
     }
  }
  // Execute the following code after breaking out of the for loop above.
  SomeOtherFunction();
}

问题是在之后//做一些在这里工作。语句执行,我想退出for循环但仍想执行整个for循环下面的代码(下面的所有内容//在爆发后执行以下代码上面的for循环。)。

The problem is that after the // Do some work here. statements executes, I want to exit the for loop but still want to execute the code below the whole for loop (everything below // Execute the following code after breaking out of the for loop above.).

return false 语句确实退出for循环但它也退出整个函数。我该如何解决这个问题?

The return false statement does exit the for loop but it also exits the whole function. How do I fix this?

推荐答案

您正在寻找 break statement

You're looking for the break statement.

这篇关于javascript退出for循环而不返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆