Learn C Programming

Lesson 7 of 9 · Loops and Jump Statements

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

  1. Off by one: a loop that runs once too many or once too few
  2. The infinite loop: nothing moves the condition
  3. Reading Time limit exceeded: never ends, or ends too late
  4. The Zune freeze: a path through the body that takes no step
  5. The unsigned countdown that never ends
  6. The stray semicolon after the header
  7. The missing brace
  8. The loop variable changed in the body
  9. One equals sign in the condition
  10. What GCC 12 says about each bug
  11. The five-question loop checklist