Practice question · True or false
An off-by-one error in a loop boundary usually causes a crash, which is what makes it easy to find.
Hints
- What happens if the loop simply skips the last item?
- A wrong answer is quieter than a crash.
Show the answer
False
Why
False. Off-by-one errors usually produce a wrong result — one item skipped, one processed twice — with no crash at all, which is exactly what makes them hard to find. They surface as a total that is slightly off, and only an out-of-range index turns one into an exception.
Practise Loops and Repeated Computation
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Loops and Repeated Computation
- Order the parts of a correct while loop so that it counts up and then stops.
- Match each loop keyword or form to what it does.
- Modifying a list while looping over it can silently skip elements. Why does removing an item mid-iteration…
- The counter starts at i = 0. Select every loop below that runs its body exactly 5 times.