Skip to content
Computer Science · Grade 10

Active learning ideas

Looping Structures (While/For)

Active learning works well for looping structures because students need to visualize repetition and internalize how conditions control flow. By physically tracing loops on paper, debugging code together, and predicting outputs before coding, students build mental models that prevent common pitfalls like infinite loops or off-by-one errors.

Ontario Curriculum ExpectationsCS.HS.A.2CS.HS.P.1
25–45 minPairs → Whole Class4 activities

Activity 01

Stations Rotation30 min · Pairs

Pair Programming: Loop Comparisons

Pairs receive a task like summing a list of numbers. First, code it with a while loop using a counter; then rewrite with a for loop. Discuss differences in structure, readability, and when to use each. Test both versions with varied inputs.

Compare the appropriate use cases for 'while' loops versus 'for' loops.

Facilitation TipDuring Pair Programming: Loop Comparisons, ask pairs to switch roles after every 5 minutes to keep both partners engaged with loop logic.

What to look forPresent students with two short code snippets, one using a 'while' loop and one using a 'for' loop, both achieving the same result (e.g., printing numbers 1-5). Ask students to identify which loop is more appropriate for the task and explain why in one sentence.

RememberUnderstandApplyAnalyzeSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 02

Stations Rotation45 min · Small Groups

Small Groups: Nested Pattern Builders

Groups use nested for loops to print patterns, such as multiplication tables or star pyramids, in a console. Predict row counts before coding, then alter loops for new sizes. Share screens to compare outputs.

Construct a loop to process a collection of data.

Facilitation TipFor Small Groups: Nested Pattern Builders, provide grid paper and colored pencils to help students map iterations visually before coding.

What to look forProvide students with a Python code snippet containing a 'while' loop with a potential infinite loop error. Ask them to: 1. Identify the line of code causing the infinite loop. 2. Explain how to fix it. 3. Predict what would happen if the loop ran for 10 iterations.

RememberUnderstandApplyAnalyzeSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 03

Stations Rotation25 min · Whole Class

Whole Class: Output Prediction Challenge

Display 6-8 code snippets with loops on the board. Students write predicted outputs individually for 5 minutes, then vote in teams. Run code live to reveal results and trace errors as a class.

Predict the output of a program containing nested loop structures.

Facilitation TipIn Whole Class: Output Prediction Challenge, have students hold up whiteboards after 30 seconds of thinking to reveal their predictions, then discuss discrepancies.

What to look forPose the following question: 'Imagine you are writing a program to calculate the average score from a list of 20 quiz grades. Would you use a 'for' loop or a 'while' loop? Justify your choice and explain how you would structure the loop.' Facilitate a brief class discussion on their reasoning.

RememberUnderstandApplyAnalyzeSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 04

Stations Rotation35 min · Individual

Individual: Data Processing Loops

Students code a program to process a list of student scores: use a for loop to calculate averages, while loop for validation checks. Input test data and debug independently before peer review.

Compare the appropriate use cases for 'while' loops versus 'for' loops.

Facilitation TipIn Individual: Data Processing Loops, circulate with a checklist to note which students default to while loops even when for loops are more appropriate.

What to look forPresent students with two short code snippets, one using a 'while' loop and one using a 'for' loop, both achieving the same result (e.g., printing numbers 1-5). Ask students to identify which loop is more appropriate for the task and explain why in one sentence.

RememberUnderstandApplyAnalyzeSelf-ManagementRelationship Skills
Generate Complete Lesson

A few notes on teaching this unit

Teachers should emphasize tracing loops on paper or whiteboards before running code, as this builds debugging habits and reinforces how conditions change state. Avoid rushing to code; instead, focus on dry runs for each loop type. Research shows that students who manually simulate loops first transfer these skills to debugging more effectively than those who code immediately.

Students will confidently choose between while and for loops based on task requirements, construct loops to process data sets, and accurately predict outputs from nested loops. Evidence of success includes clear explanations of loop conditions, correct handling of edge cases, and the ability to justify loop design choices.


Watch Out for These Misconceptions

  • During Pair Programming: Loop Comparisons, watch for students who assume while loops are always risky and for loops are always safe.

    Have pairs trace both loops on paper side by side, marking each condition change and iteration step to observe how each loop stops. Ask them to swap snippets and debug each other's traces to reinforce that both loop types require careful condition checking.

  • During Small Groups: Nested Pattern Builders, watch for students who think for loops only work with numeric ranges.

    Provide groups with mixed data types (lists of strings, tuples of numbers) and ask them to process each using a for loop. Have them present how the loop variable changes with each iteration to highlight that for loops adapt to any iterable.

  • During Whole Class: Output Prediction Challenge, watch for students who assume nested loops always produce exponential growth in output.

    Give students a 2x3 grid to sketch iterations before they predict outputs. Afterward, have them compare their sketches to the actual outputs to see that nesting multiplies iterations linearly per level, not exponentially.


Methods used in this brief