Javascript内的开关用于循环中断;冲突
我在JavaScript中使用循环嵌套开关,如:Javascript内的开关用于循环中断;冲突,javascript,design-patterns,Javascript,Design Patterns,我在JavaScript中使用循环嵌套开关,如: 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.
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 )
}
for(变量i=0;i
如果!sscripts是falsy,我要求用户是否要继续其他复选框,如果他取消,我要中断循环并执行函数中的其余语句。好像要休息;在执行for开关的确认对话框中,如何使其运行for循环
如果您有任何建议,我们将不胜感激。请不要使用此选项
continue; else break; //else return
试试这个
继续;否则,我就要分手代码>//与标签断开
将此标签添加到您希望控件的位置
Example
for(...)
{
switch('a')
{
case 'a': break iWantHere; // This will exit out of loop
default:
}
}
iWantHere :
// Rest of your code
这正是我们的目的:
theloop:
对于(var i=0;i
谢谢,这很有效,但这是一个好的做法吗?goto结构从来都不是首选的结构。您的链接建议使用函数,您能详细说明一下吗?
theloop:
for (var i = 0; i < checkBoxIds.length; i++) {
...
switch (id.substring(id.length - 3)) {
...
break theloop;
// continue theloop;