[prev] 26 [next]

Locating the Bug

A simple search strategy for debugging is as follows:
  • initially the whole program is "suspect"
  • put a print statement in the middle of the suspect part of the program to display values of variables at that point
  • if the values are correct, then the bug must be in the second part of the execution
  • if the values are incorrect, the bug is in the first half
  • now restrict your attention to just the relevant half of the program (it becomes the new "suspect part of the program")
  • repeat the above steps