核心知识
while 循环
while 在条件为真时持续执行,适合次数事先不确定的过程。
- 循环应有可达的退出路径:条件变假、break 或 return 等
- 先检查条件,可能一次也不执行
- 警惕无限循环
let attempts = 0;
while (attempts < 3) {
attempts += 1;
}
while 在条件为真时持续执行,适合次数事先不确定的过程。
let attempts = 0;
while (attempts < 3) {
attempts += 1;
}