for循环中断的Javascript切换;冲突 [英] Javascript switch within for-loop break; conflicts

查看:115
本文介绍了for循环中断的Javascript切换;冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaScript中使用循环嵌套切换,如:

I have switch nested with loop in JavaScript like:

for (var i = 0; i < checkBoxIds.length; i++) {
        if ($('#' + checkBoxIds[i]).prop('checked')) {
            var id = checkBoxIds[i];
            var assetCat = id.substring(0, 4);
            switch (id.substring(id.length - 3)) {
                case "scr":
                    if (!sscripts)
                        if (confirm("Name of scripts sub-folder (in shared) is not provided for " + assetCat + ". Press OK to Continue for others?"))
                            continue; else break; //else return
                    //Appending chrs or sets or props to scripts
                    switchAssets(sscripts, IdEnum.SCRIPTS);
                    break;
                case "shd":
                    if (!sshaders)
                        if (confirm("Name of shaders sub-folder (in shared) is not provided for " + assetCat + ". Press OK to Continue for others?"))
                            continue; else break; //else return
                    //Appending chrs or sets or props to shaders
                    switchAssets(sshaders, IdEnum.SHADERS);
                    break;
                case "sim":
                    if (!ssourceimages)
                        if (confirm("Name of sourceimages sub-folder (in shared) is not provided for " + assetCat + ". Press OK to Continue for others?"))
                            continue; else break; //else return
                    //Appending chrs or sets or props to sourceimages
                    switchAssets(ssourceimages, IdEnum.SOURCEIMAGES);
                    break;
                default:
            }
        }
    }

    //...Still doing something (else return; will never kiss this :D )
}

如果!sscripts 是假的,我要求用户如果想继续使用其他复选框,如果取消,我想打破循环并在函数中执行剩余的语句。好像是休息;在执行switch的确认对话框中,如何让它为for循环运行。

if !sscripts is falsy, i am asking user to if want to continue for other check-boxes, if he cancels, i want to break the loop and execute remaining statements within a function. Seems like break; within confirm dialog executing for switch, how can i make it to run for for-loop.

任何建议都将受到赞赏。

Any suggestions will be appreciated.

推荐答案

这正是什么标签适用于:

theloop:
  for (var i = 0; i < checkBoxIds.length; i++) {
    ...

    switch (id.substring(id.length - 3)) {

      ...
        break theloop;
        // continue theloop;

这篇关于for循环中断的Javascript切换;冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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