<i id='R5JHd'><tr id='R5JHd'><dt id='R5JHd'><q id='R5JHd'><span id='R5JHd'><b id='R5JHd'><form id='R5JHd'><ins id='R5JHd'></ins><ul id='R5JHd'></ul><sub id='R5JHd'></sub></form><legend id='R5JHd'></legend><bdo id='R5JHd'><pre id='R5JHd'><center id='R5JHd'></center></pre></bdo></b><th id='R5JHd'></th></span></q></dt></tr></i><div id='R5JHd'><tfoot id='R5JHd'></tfoot><dl id='R5JHd'><fieldset id='R5JHd'></fieldset></dl></div>
        <bdo id='R5JHd'></bdo><ul id='R5JHd'></ul>

    1. <legend id='R5JHd'><style id='R5JHd'><dir id='R5JHd'><q id='R5JHd'></q></dir></style></legend>

        <tfoot id='R5JHd'></tfoot>
      1. <small id='R5JHd'></small><noframes id='R5JHd'>

        return 会停止循环吗?

        时间:2023-09-04
        • <tfoot id='QG80Q'></tfoot>

            <tbody id='QG80Q'></tbody>
          <i id='QG80Q'><tr id='QG80Q'><dt id='QG80Q'><q id='QG80Q'><span id='QG80Q'><b id='QG80Q'><form id='QG80Q'><ins id='QG80Q'></ins><ul id='QG80Q'></ul><sub id='QG80Q'></sub></form><legend id='QG80Q'></legend><bdo id='QG80Q'><pre id='QG80Q'><center id='QG80Q'></center></pre></bdo></b><th id='QG80Q'></th></span></q></dt></tr></i><div id='QG80Q'><tfoot id='QG80Q'></tfoot><dl id='QG80Q'><fieldset id='QG80Q'></fieldset></dl></div>
          <legend id='QG80Q'><style id='QG80Q'><dir id='QG80Q'><q id='QG80Q'></q></dir></style></legend>

              <bdo id='QG80Q'></bdo><ul id='QG80Q'></ul>

              <small id='QG80Q'></small><noframes id='QG80Q'>

                  本文介绍了return 会停止循环吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有一个这样的循环:

                  Suppose I have a loop like this:

                  for (var i = 0; i < SomeArrayOfObject.length; i++) {
                  
                    if (SomeArray[i].SomeValue === SomeCondition) {
                  
                       var SomeVar = SomeArray[i].SomeProperty;
                       return SomeVar;
                    }
                  }
                  

                  快速提问:return 本身会停止循环的执行吗?

                  Quick question: does the return stop the execution of the loop in and of itself?

                  推荐答案

                  是的,return 停止执行并退出函数.return always** 立即退出其函数,如果它在 for 循环中则不再执行.

                  Yes, return stops execution and exits the function. return always** exits its function immediately, with no further execution if it's inside a for loop.

                  很容易自己验证:

                  function returnMe() {
                    for (var i = 0; i < 2; i++) {
                      if (i === 1) return i;
                    }
                  }
                  
                  console.log(returnMe());

                  ** 注意:请参阅 this other answer 关于 try/catch/finally 的特殊情况code> 和 this answer 关于 forEach 循环如何它自己的函数范围不会脱离包含函数.

                  ** Notes: See this other answer about the special case of try/catch/finally and this answer about how forEach loops has its own function scope will not break out of the containing function.

                  这篇关于return 会停止循环吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    <small id='tMPKT'></small><noframes id='tMPKT'>

                    <tfoot id='tMPKT'></tfoot>

                  1. <i id='tMPKT'><tr id='tMPKT'><dt id='tMPKT'><q id='tMPKT'><span id='tMPKT'><b id='tMPKT'><form id='tMPKT'><ins id='tMPKT'></ins><ul id='tMPKT'></ul><sub id='tMPKT'></sub></form><legend id='tMPKT'></legend><bdo id='tMPKT'><pre id='tMPKT'><center id='tMPKT'></center></pre></bdo></b><th id='tMPKT'></th></span></q></dt></tr></i><div id='tMPKT'><tfoot id='tMPKT'></tfoot><dl id='tMPKT'><fieldset id='tMPKT'></fieldset></dl></div>
                        <tbody id='tMPKT'></tbody>

                          <bdo id='tMPKT'></bdo><ul id='tMPKT'></ul>
                        • <legend id='tMPKT'><style id='tMPKT'><dir id='tMPKT'><q id='tMPKT'></q></dir></style></legend>