Computer Science Grade 3 20 min

Step-by-Step Debugging: Following the Code

Students will learn how to step through their code line by line to find errors.

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define 'bug' and 'debugging' in their own words. Read a short sequence of code one line at a time. Predict the outcome of a simple program by following its steps. Identify a bug in a sequence of instructions by tracing the code's path. Explain what a conditional statement (If/Then) does in a program. Correct a simple bug by changing one line of code. Have you ever followed a recipe to bake cookies, but they came out all wrong? 🍪🔍 Let's be detectives and find out what went wrong in our code recipes! Today, we'll learn how to be 'Code Detectives'! We will learn a special skill called step-by-step debugging, which is like reading a story one sentence at a time to find a mistake. This helps us fix our code and m...
2

Key Concepts & Vocabulary

TermDefinitionExample BugA mistake or error in the code that stops a program from working the way it should.You tell a robot to move forward, but it moves backward instead. The mistake in the code is the bug. DebuggingThe process of finding and fixing bugs in your code. It's like being a detective for your program!You look at your robot's code, find the line that says 'move backward', and change it to 'move forward'. That's debugging! Step-by-StepFollowing the code one line at a time, in the correct order, without skipping any steps.To debug, you read Line 1, then Line 2, then Line 3, and so on, to see exactly what the computer is doing. Code BlockA piece of code that does one specific job. It's like a paragraph in a story.A block of code might tell...
3

Core Syntax & Patterns

The One-Step-at-a-Time Rule Read and act out each line of code in order, from top to bottom. Use this rule to carefully follow what the computer will do. Don't jump ahead or guess! Point to each line with your finger as you read it. The Pretend Computer Rule Pretend you are the computer. You can only do EXACTLY what the code tells you to do. This helps you find bugs because computers don't know what you *meant* to write, only what you *did* write. If the code says 'turn left', you must turn left, even if you wanted to go right.

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
A player needs a score of 10 AND a key to open a chest. The code is: 'IF score > 9 THEN IF has_key = true THEN OPEN chest'. The player has a score of 15, but has_key is false. What happens?
A.The chest opens.
B.The program checks if has_key is true, then stops.
C.The program checks if score > 9, then stops.
D.The program shows an error message.
Challenging
A character collects coins. The code is: 'WHEN coin is touched: CHANGE score by 1. HIDE coin.' The player's score is not increasing, but the coins are disappearing. Where is the most likely bug?
A.The 'HIDE coin' block is running before the 'CHANGE score' block.
B.The 'score' variable was never created or set to 0 at the start.
C.The player is moving too fast to collect the coins.
D.The coins are not the right color.
Challenging
A game has a cat and a dog. Cat's code: 'WHEN I receive "chase", MOVE 10 steps.' Dog's code: 'WHEN space key PRESSED, BROADCAST "chase".' The player presses the space key, but only the dog moves. Why isn't the cat moving?
A.The cat's code has a bug.
B.The dog's code should say 'BROADCAST "run"'.
C.The dog is moving, but the problem description is wrong.
D.The dog's code is missing a 'MOVE 10 steps' block.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Debugging Detectives: Solving Code Mysteries

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.