Breakpoints, Go, and Quit
00:00 In the previous lesson, you’ve used Step, Out, and Over to step through your code, more or less line by line. Often, however, you may know that the bug must be in a particular section of your code, but you probably don’t know exactly where.
00:16 And then, rather than clicking Step all day long, you can set a breakpoint that tells the debugger to continuously run all the code until it reaches the breakpoint. In this lesson, you’ll set a breakpoint and you’ll use the Go button to inspect certain parts of your script more specifically. And by the way, breakpoints just tell the debugger when to pause code execution so that you can take a look at the current state of the program. They don’t actually break anything.
00:45 To set a breakpoint, click on the line of code that you want to set it on and do a right-click, or Control-click on Mac, then select the option Set Breakpoint. IDLE highlights the line in yellow to indicate that your breakpoint has been set. To remove a breakpoint, do the same, but select Clear Breakpoint.
Now, go ahead and run your file again, pressing F5. The interactive window will tell you that this is a restart, and the debugger is still on. At the same time, you’ll also see that the buttons in the Debug Control window are interactive again. And just as before, you can see that in the Stack panel, the debugger tells you
'__main__'.<module>(), line 1: for i in range(1, 4):.
02:00 So again, the debugger stopped just before executing line 1 of your script. Now, instead of stepping through your code using Step, you will use the Go button that, in combination with a breakpoint, will run the code until it hits a breakpoint.
So go ahead and press Go and then inspect the state of your Debug Control window. You can see the Stack now tells you that it stopped just before line 3, instead of line 3 as before, when you used the Step button. Also, inside of your Globals panel, you can see that both
j are already defined.
If you press Go again, then Python will continue running the
for loop until it hits the next breakpoint, which is just before the next
print() function. As a result, you can see
i is 1 and j is 2 printed to your interactive window, and you can also see that the variables
j have both changed, and now point to the values
03:21 Now, just as before, if you press Go once more, then your program is going to run to the end and finish. And just to try out the Quit button, instead of running this final iteration of the loop, you will press Quit and see what changes there.
Become a Member to join the conversation.