简体   繁体   English

Javascript返回值,不中断循环

[英]Javascript Return Value without breaking loop

My code is currently as follows. 我的代码当前如下。 I'm using the Parse.Js library. 我正在使用Parse.Js库。

while (i < workout) {

    return q.find({
        success: function (type) {
            if (type == 3) {
                typeCount++;
            }
        }
    });
    i++;
}

The problem is the 'return' seems to stop the rest of the function from working. 问题在于“返回”似乎使其余功能无法正常工作。 Is there a way to do this without breaking the loop? 有没有办法做到这一点而又不中断循环?

I tried removing the return all together but then the q.find code doesn't run. 我尝试一起删除所有返回值,但是q.find代码无法运行。

不行return结束函数的执行,中断所有循环, if块等,您可以将值存储在变量中,并在结束时返回值(一旦循环完成),但是return停止函数。

没有,您可以将值添加到数组中,然后返回该数组,而不是“返回”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM