← VCE Software Development U3O1

Stepping through code and watching variables

Run paused code one line at a time using step over, step into or step out, while the watch panel shows each variable change, to find where a value goes wrong.

Understanding Stepping through code and watching variables in VCE Software Development U3O1

What it does: A watch entry names a variable or expression and displays its live value as you step through the code. Continue lets you jump to the next breakpoint instead of stepping line by line, which is useful once you have checked a section. Step into moves the debugger into the called function so you can run its lines one at a time. The first line where a value differs from what you expected is the clue. The bug is on that line or just before it. Step over treats a function call as one single step and does not go inside the function.

Common mistakes: Stepping over this line makes the watch panel show discount as 200, not 2. A 10% discount needs price * 0.1, not price / 0.1. The watch panel lists a variable called total, not totl. Stepping onto this line raises a NameError. It should be print(n, total).

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 168–177) and word search (Modules 168–193).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A program is paused at a breakpoint on the line total = add_up(prices). You want to run the whole add_up() call as one step and stay in the current function. Which do you use?
Step intoStep over
Matches
Step Into on print(total) to check why total is wrong
↓
Step into on a built-in function like print() goes into library code you don't need. Use step over, then check total in the watch panel.
Applying
Meanings
Term
step through
Meaning
Run paused code one line at a time using step over, step into or step out, while the watch panel shows each variable change, to find where a value goes wrong.
Practice
total = 0
Testing
Gaps
()
Check Answer
Spots
1price = 20
2discount = price / 0.1

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Silverback Gorilla' badge — Savannah Master, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A program is paused at a breakpoint on the line total = add_up(prices). You want to run the whole add_up() call as one step and stay in the current function. Which do you use?
A. Step over ✓
B. Step into
Step over runs the called function in one go and pauses on the next line of your current code. Step into would jump inside add_up().
2. You are paused on a line that calls calculate_tax(), and you suspect the mistake is inside that function. Which do you use?
A. Step over
B. Step into ✓
Step into moves the debugger into the called function so you can run its lines one at a time.
3. You have stepped into a function and checked it. The rest of it looks fine. Which do you use to finish it and return to the code that called it?
A. Step into
B. Step out ✓
Step out runs the remaining lines of the current function and pauses back in the caller.
4. What is the job of the watch panel (variables panel) while you step through code?
A. It shows the current value of variables so you can see them change after each line ✓
B. It automatically fixes any line where a variable has the wrong value
The watch panel only displays values. You still have to spot the line where a value first goes wrong and fix it yourself.
5. You step through a loop and watch the variable count. It should be 3 after the third line runs, but the watch panel shows 5. What is the best conclusion?
A. The error happened on or before this line, so look at the last line that changed count ✓
B. The error must be on the last line of the program
The first line where a value differs from what you expected is the clue. The bug is on that line or just before it.

Match the Pairs

Step Over → Runs the current line in full, including any function it calls, then pauses on the next line in the same function.
Step Into → Moves into the function being called on the current line and pauses on that function's first line.
A watch window shows the current value of a variable at each pause, so you can see when it changes. → Watch: total = 45
Continue runs the program from a pause until it reaches the next breakpoint, skipping the lines in between. → Continue (F5)
Step Into on print(total) to check why total is wrong → Step into on a built-in function like print() goes into library code you don't need. Use step over, then check total in the watch panel.
Stepping through 500 loop passes with Step Over, one line at a time, to reach the last pass → Stepping line by line through every pass is slow. Set a breakpoint after the loop and use Continue, or watch the variable to find the line where its value goes wrong.

Key Term

step through
Run paused code one line at a time using step over, step into or step out, while the watch panel shows each variable change, to find where a value goes wrong.

Fill in the Blanks

1. total = 0 breakpoint() total = total + 5
Hint: Type the built-in function name that pauses the program so you can step through it.
2. total = total + 5 (Pdb) next
Hint: Type the command that steps over the current line and moves to the next one without entering any function.
3. total = add(2, 3) (Pdb) step
Hint: Type the command that steps into the function call so you can run its lines one at a time.
4. (Pdb) display total
Hint: Type the command that adds a variable to the watch list so its value shows after every step.
5. (Pdb) continue
Hint: Type the command that stops stepping and runs on until the next breakpoint is reached.

Spot the Error

Question 1
A price = 20
B discount = price / 0.1
C final = price - discount
D print(final)
Line B — Stepping over this line makes the watch panel show discount as 200, not 2. A 10% discount needs price * 0.1, not price / 0.1.
Question 2
A total = 0
B for n in range(1, 4):
C total += n
D print(n, totl)
Line D — The watch panel lists a variable called total, not totl. Stepping onto this line raises a NameError. It should be print(n, total).
Question 3
A width = 4
B height = 3
C area = width + height
D print(area)
Line C — After stepping over this line, the watch window shows area as 7 when it should be 12. The area of a rectangle uses width * height, not +.
Question 4
A score = '0'
B for i in range(3):
C score += 5
D print(score)
Line A — The watch panel would show score as the string '0'. Stepping over line 3 then fails because you cannot add an integer to a string. It should be score = 0.
Question 5
A def double(n):
B return n + 2
C x = double(4)
D print(x)
Line B — Step into double() and watch n is 4, but the returned value is 6, not 8. Doubling needs n * 2, not n + 2.

Student with a class code? Join your class →