Have students pay close attention to loop bounds when tracing through code to help them identify and avoid off-by-one errors caused this way.

  • Students don’t always keep close track of the loop counter when tracing through loops.
    • Students may stop incrementing the loop counter before the loop condition has been met.
    • Alternatively, students may continue to increment the loop counter after the loop condition is satisfied.
  • This can be a result of not understanding at what point in the loop conditions are checked or mixing up < and <=.

More about this tip

External Source

Leigh Ann Sudol-DeLyser’s notes from 2009 AP CS A exam.