如何退出(转义)从循环里面的功能呢? [英] How to exit (escape) a function from for loop inside of it?

查看:119
本文介绍了如何退出(转义)从循环里面的功能呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对此感到困惑,因为我是这样理解的卡在代码
如何逃避for ...每个循环和方法在同一时间?

我不能停止迭代选项中选择元素。



我试过返回返回false 已经是,但是我没有成功。

一般我们可以做什么()...

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ){
$(...)。each(function(){
//你必须从这里退出外部函数
});




$ div class =h2_lin>解决方案

在循环之间使用共享变量。如果你想退出,在 each()循环的末尾将它翻转为 true for-loop 检查它是 true 。如果是的话,打破它。


This is theoretical question to understand how many escapes (return or exit) can apply to nested loops or other controls and functions.

I confused about this because I am stuck in the code How to escape from for ... each loop and method at the same time?

I can't stop iterating over options in select element.

I tried return and return false already, but am unsuccesful.

Generally how we can do that?

function() {
    for (...) {
        if (...) {
            $(...).each(function() {
               // You have to exit outer function from here
            });
        }
    }
}

解决方案

Use a shared variable between the loops. Flip it to true at the end of the each() loop if you want to exit and at the end of the for-loop check for it being true. If yes, break out of it.

这篇关于如何退出(转义)从循环里面的功能呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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