核心知识
break 与 continue
break 结束整个循环,continue 跳过本次剩余语句进入下一次。
- 只在明确条件使用
- 过多跳转会降低可读性
- 先考虑能否改写条件
for (const score of scores) {
if (score == null) continue;
if (score < 0) break;
}
break 结束整个循环,continue 跳过本次剩余语句进入下一次。
for (const score of scores) {
if (score == null) continue;
if (score < 0) break;
}