我有一个 for 循环,我想像这样退出:
function MyFunction() {
for (var i = 0; i < SomeCondition; i++) {
if (i === SomeOtherCondition) {
// Do some work here.
return false;
}
}
// Execute the following code after breaking out of the for loop above.
SomeOtherFunction();
}
问题是// Do some work here.
语句执行后,我想退出 for 循环,但仍想执行整个 for 循环下面的代码(下面的所有内容// Execute the following code after breaking out of the for loop above.
)。
该return false
语句确实退出了 for 循环,但它也退出了整个函数。我该如何解决?