gpt4 book ai didi

javascript for (i = 0; i < XXX.length; i++) -> 长度问题

转载 作者:行者123 更新时间:2023-11-29 22:40:48 25 4
gpt4 key购买 nike

for (m = 0; m < troopsCount.length; m++) {

//FM_log(7,"i="+i+" m="+m);
//FM_log(7,"tipoTropaPrioritaria[m] = "+tipoTropaPrioritaria[m]);
//FM_log(7,"troopsCount[m] = "+troopsCount[m]);
//FM_log(7,"availableTroops[m] = "+availableTroops[m]);

if ((tipoTropaPrioritaria[m] == null || tipoTropaPrioritaria[m] == "undefined")
|| (troopsCount[m] == null || troopsCount[m] == "undefined") ||
(availableTroops[m] == null || availableTroops[m] == "undefined"))
return "alternaTropas(): ERRO - tipoTropaPrioritaria[m] || troopsCount[m] || availableTroops[m] null ou undefined";

if ((parseInt(tipoTropaPrioritaria[m]) != 0) && (parseInt(troopsCount[m]) != 0)) {
naoServe = true;
break;
}
else {
if ((parseInt(availableTroops[m])) < (parseInt(troopsCount[m]))) {
naoServe = true;
break;
}
else if (m < troopsCount.length) {
naoServe = true;
}
else { //means m >= troopsCount.length
naoServe = false;
}
}
}

我的问题是:最后的陈述

else { //means m >= troopsCount.length
naoServe = false;
}

从那以后它会被评估吗

for (m = 0; m < troopsCount.length; m++)

???

最佳答案

不,它不会被执行,假设 mtroopsCount 没有在循环本身中被修改(在这个例子中他们似乎没有是)。

正如我相信您所指出的,如果开始时 m 大于或等于 troopsCount.length,循环的条件将阻止循环再次运行循环的。

关于javascript for (i = 0; i < XXX.length; i++) -> 长度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2922490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com