### Step 7: Recursive Debugging

We will now start the debugging process over again in order to catch new bugs, or previously missed bugs. First, we will want to reset our breakpoints. We are no longer interested in what is happening within the `while() loop;` we are only interested in the programs state immediately before the loop and immediately after the loop. Follow these steps to set up the new breakpoints:

1. Remove all previously entered breakpoints (see "Accomplishing Common Tasks>Adding/Removing Breakpoints").
2. Add a breakpoint to line 17 of the program (see "Accomplishing Common Tasks>Adding/Removing Breakpoints").
3. Add a breakpoint to line 28 of the program (see "Accomplishing Common Tasks>Adding/Removing Breakpoints" ).

Start the debugger (see "Step 2: Running the Debugger" above). The program will stop executing on line 17. Inspect the data in the Gild Debug View:

The variable that we are interested in is `powerOfTwo`. Its value is 1, which is correct. We want to continue running the program. However, we don’t want to step through the entire program, especially when we aren’t interested in what is happening within the `while()` loop.

There is a facility that allows us to resume program execution without having to use the stepping functionality. It is called resume. Resume continues program execution from the current line. The program will continue to execute until it is completed, or until a breakpoint has been reached. We are interested in the state of the variables just after the `while()` loop, and we already have a breakpoint there. Press the "Resume" button of the Gild Debug View to run our program up to (but not including) line number 28. Now, inspect the data in the Gild Debug View:

Again, the variables have the right values. But we are not getting the right output. What we need to do is insert a line of code for output. Follow these steps:

1. Terminate your program.
2. Add the following line of code between the current lines 27 and 28:

   `System.out.println("The current power of 2 is " + powerOfTwo);`

3. Save your program.
4. Build your program.
5. Run your program.

You should be presented with the following output in the Console View at the bottom of your screen:

    The current power of 2 is 1
    The current power of 2 is 2
    The current power of 2 is 4
    The current power of 2 is 8
    The current power of 2 is 16
    The current power of 2 is 32
    2^5 = 32

This is the correct output. We have successfully debugged our program.

Previous | Next