我有 3 个 for 循环:
for (var i = 0; i < ns_match.length; i++) {
for (var j = 0; j < user_interest.length; j++) {
for (var k = 0; k < ns_match[j].data().user_interest.length; k++) {
if (user_interest[j] == (ns_match[i].data().user_interest)[k]) {
ns_score[i] += 5;
}
}
}
}
我会添加一个逻辑,例如 if (user_interest[j] == (ns_match[i].data().user_interest)[k]) {
is true,然后扩充 j.
换句话说,我正在寻找诸如以下内容: if (user_interest[j] == (ns_match[i].data().user_interest)[k]) {
if that is true,则跳出 K 循环,但在 J 循环中继续增量。
最佳答案
使用break命令跳出当前循环 block 。
如果您需要打破除最内层循环之外的其他循环,您可能需要研究所谓的“标签”
关于javascript - 继续嵌套 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58905344/