<legend id='YV5AT'><style id='YV5AT'><dir id='YV5AT'><q id='YV5AT'></q></dir></style></legend>

  1. <small id='YV5AT'></small><noframes id='YV5AT'>

      <tfoot id='YV5AT'></tfoot>
        <bdo id='YV5AT'></bdo><ul id='YV5AT'></ul>
    1. <i id='YV5AT'><tr id='YV5AT'><dt id='YV5AT'><q id='YV5AT'><span id='YV5AT'><b id='YV5AT'><form id='YV5AT'><ins id='YV5AT'></ins><ul id='YV5AT'></ul><sub id='YV5AT'></sub></form><legend id='YV5AT'></legend><bdo id='YV5AT'><pre id='YV5AT'><center id='YV5AT'></center></pre></bdo></b><th id='YV5AT'></th></span></q></dt></tr></i><div id='YV5AT'><tfoot id='YV5AT'></tfoot><dl id='YV5AT'><fieldset id='YV5AT'></fieldset></dl></div>
    2. 从Javascript中的switch case内部中断for循环

      时间:2023-09-07
        <tbody id='WQxGk'></tbody>
    3. <i id='WQxGk'><tr id='WQxGk'><dt id='WQxGk'><q id='WQxGk'><span id='WQxGk'><b id='WQxGk'><form id='WQxGk'><ins id='WQxGk'></ins><ul id='WQxGk'></ul><sub id='WQxGk'></sub></form><legend id='WQxGk'></legend><bdo id='WQxGk'><pre id='WQxGk'><center id='WQxGk'></center></pre></bdo></b><th id='WQxGk'></th></span></q></dt></tr></i><div id='WQxGk'><tfoot id='WQxGk'></tfoot><dl id='WQxGk'><fieldset id='WQxGk'></fieldset></dl></div>

        1. <tfoot id='WQxGk'></tfoot>

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

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

              1. 本文介绍了从Javascript中的switch case内部中断for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                必须用什么命令,才能跳出for循环,也是从//code inside直接跳转到//code after

                What command I must use, to get out of the for loop, also from //code inside jump direct to //code after

                //code before
                for(var a in b)
                    {
                    switch(something)
                        {
                        case something:
                            {
                            //code inside
                            break;
                            }
                        }
                    }
                //code after
                

                推荐答案

                不幸的是,Javascript 不允许 break 遍历多个级别.最简单的方法是通过创建匿名函数来利用 return 语句的强大功能:

                Unfortunately, Javascript doesn't have allow breaking through multiple levels. The easiest way to do this is to leverage the power of the return statement by creating an anonymous function:

                //code before
                (function () {
                    for (var a in b) {
                        switch (something) {
                        case something:
                            {
                                //code inside
                                return;
                            }
                        }
                    }
                }());
                //code after
                

                这是可行的,因为 return 离开了函数,因此隐式地离开了循环,将您直接移动到 code after

                This works because return leaves the function and therefore implicitly leaves the loop, moving you straight to code after

                正如评论中指出的那样,我上面的答案是不正确的,可以进行多级breaking,如Chubby Boy 的回答,我已投赞成票.

                As pointed out in the comments, my above answer is incorrect and it is possible to multi-level breaking, as in Chubby Boy's answer, which I have upvoted.

                这是否是明智的,从七年后的角度来看,有点值得怀疑.

                Whether this is wise is, from a seven-year-later perspective, somewhat questionable.

                这篇关于从Javascript中的switch case内部中断for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:if-else、switch 或 map based 条件的性能 下一篇:Jquery 和 List 中的 switch 语句

                相关文章

                    <bdo id='2toVL'></bdo><ul id='2toVL'></ul>
                1. <small id='2toVL'></small><noframes id='2toVL'>

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

                  1. <tfoot id='2toVL'></tfoot>