Exercise 4: Stepping Through a Method

Stepping through your code is another way to get to the line that is causing a problem. In this exercise, you will learn to step through code and track the changes in variable values in the Threads/Stack tab. You will also learn how to remove a breakpoint.

  1. Bring the Source Editor to the front.

  2. Click the Step Over control in the Source Editor tool bar.
    The WorkShop executes one source line and stops in:

    If (Math.random() < 0.5) {

    The Source Editor highlights the line with the breakpoint in red and the line in which program execution stopped in green. If the line had been a method call, the Step Over command would run to the next line in the program. If the line had been a method call and you issued the Step Into command, the WorkShop would execute the first statement of the method and stop.

    The Threads/Stack tab shows the current state of the program and its data. For example, Blink.paint now indicates it is stopped in line 49.

  3. Click the Step Over control two more times and watch how the Debugger steps through your program.

  4. In the Source Editor, move the pointer to the line 45, which has a breakpoint.

  5. Click the Toggle Breakpoint control .
    The WorkShop removes the breakpoint.

Next lesson:

Exercise 5: Evaluating Variables