Module 6 · Loops and Jump Statements
Bug Gallery: Off by One, Infinite, and the Missing Brace
ProReading
Bob wrote five loops after lunch. One printed a seat list one short, and one never stopped. One ran its body once, one forgot two marks, and one would not let the till close. Bob calls it a productive afternoon.
Checking what this lesson needs for you…
What is inside Bug Gallery: Off by One, Infinite, and the Missing Brace
- Off by one: a loop that runs once too many or once too few
- The infinite loop: nothing moves the condition
- Reading Time limit exceeded: never ends, or ends too late
- The Zune freeze: a path through the body that takes no step
- The unsigned countdown that never ends
- The stray semicolon after the header
- The missing brace
- The loop variable changed in the body
- One equals sign in the condition
- What GCC 12 says about each bug
- The five-question loop checklist