Grade 7 · Technology, computer science and digital literacy · 25 minutes
Unit 1 · Logic and Information Quality · Lesson 1 of 2
Trace a Conditional Algorithm
Trace an if/else rule and a repeated action using small supplied inputs.
Mr. S Teaches · Original starter mini-lesson · MS7-TECH-01 · Elective / rotation; availability variesLearning objective
Predict the outputs of a conditional algorithm for four inputs and explain the boundary case using precise terms.
Before you begin
- Follow numbered instructions and identify an input and output.
Gather your materials
- Paper
- Pencil
- Four input cards labeled 0, 1, 2 and 3
Language to know
- Condition
- A statement a program tests as true or false.
- Branch
- A path chosen when a condition is tested.
- Loop
- Instructions repeated according to a rule.
- Output
- A result produced by an algorithm.
Understand the concept
An algorithm can choose a branch. This fictional badge algorithm takes a whole-number input n from 0 to 3. If n is at least 2, set color to blue; otherwise set color to green. Then repeat n times: draw one dot. Output the color and the row of dots. The color decision and repetition answer different questions. “At least 2” includes 2. When n = 0, repeating zero times draws no dots; it does not mean repeat forever. Trace each instruction in order rather than guessing from a pattern.
Teach it step by step
- Copy the input limit and algorithm. Underline “at least 2” and say which values make it true.
- Trace n = 2: choose the branch first, then count two repetitions and record the output.
- Trace n = 0, 1 and 3 with input, condition result, color and dot count as column headings.
- Write a technical explanation using condition, branch, loop and output accurately. Explain why n = 2 is a useful boundary test.
Make the thinking visible
Worked example or model response
For n = 2, the condition 2 ≥ 2 is true, so the blue branch is chosen; the loop draws two dots. For n = 1, it is false, so the output is green with one dot. Choosing green for n = 2 would reveal a boundary error.
Guided practice
Together test a draft description that says “if n is greater than 2.” Compare its output at n = 2 with the original algorithm and name the changed condition.
Independent practice
Complete the four-row trace table for inputs 0–3 and write four sentences explaining the decisions and repeated action. Add a test for n = 4 and explain why the input specification matters before predicting a supported output.
Quick assessment
Is “repeat n times” the same instruction as “repeat until n changes”? Explain with n = 0.
Answer key & assessment criteria
Answers and teaching guidance
- Guided: With greater than 2, n = 2 takes the green branch rather than blue. The inequality changed from ≥ to >.
- Independent: n=0 → green, no dots; n=1 → green, one dot; n=2 → blue, two dots; n=3 → blue, three dots. Input 4 is outside the stated supported range, so the specification must be extended before treating its result as a required behavior.
- Quick check: No. A count-controlled loop with n=0 runs zero times. “Until n changes” depends on a stopping condition and could fail to stop if no instruction changes n.
Look for: Look for accurate tracing and explanation of boundary conditions. No programming syntax or online account is required.
Make it work for your learner
More support
Use colored branch cards with text labels as well as color, and move one counter for each loop repetition.
Extension challenge
Change the color rule to “n is even.” Specify what happens at zero, trace all four inputs again and compare branch decisions.
Selected contributions · Official sources
Standards connections
Subject-content alignment not yet verified
Supporting Common Core connection
W.7.2.dCommon Core · Grade 7
Use computing vocabulary precisely to explain algorithm behavior.
Read the official standard ↗The explanation practices domain language; it does not establish verified computer-science content standards or full programming competence.
Source and mapping checked 2026-11-04. This mini-lesson contributes selected skills; it does not claim full attainment.
