Just as manually instrumenting code helped us understand and debug statements, it can also help us understand and debug loops. Manually instrumenting loops has the dual disadvantages of requiring us to insert output statements when exploring a program's behavior and removing them when we are finished. Instrumentation still works with loops that primarily perform some calculation, like the while-loop in the gcd example. However, when the loop produces output during each iteration, the loop and instrumentation outputs are intermixed, making it difficult to read and understand either output. Worse still is the case where the output's formatting is a significant part of the solution (as with multtab). These situations are where the debugger demonstrates its value.
We'll use multtab, a program written previously in this chapter, to demonstrate some new debugger features. There are several reasons for choosing multtab.
It's small so that we can focus on the example, not the program.
Second, it has nested loops whose behavior we can more easily understand with a debugger, demonstrating its usefulness.
And finally, it generates console output during each iteration, making manual instrumentation more difficult to use.
The following screen captures show which controls to use but cannot show the debugger's full dynamic behavior. Watch the accompanying video to see better how the debugger operates.