Spot 循环 Mistake
找错误 简单
题目
这个循环是 supposed 到 print 'hello' three 次数, 但它 仅 prints 两次. 什么是 错误?
代码
for (let i = 0; i < 2; i++) {
console.log("hello");
}
提示
如何许多值 做 i take: 0, 1 — 那个是 仅 two iterations.
解释
With i < 2, i takes values 0 and 1 — only two iterations, so "hello" prints twice. To print three times, change the condition to i < 3 (i = 0, 1, 2) or i <= 2. This is a classic off-by-one error, the most common bug in loop logic.
相关资源
相关课程
- 循环 (for & 虽然)
学习如何 for and 虽然循环工作.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。