Skip to content
Computing · Secondary 3

Active learning ideas

Iteration: While Loops

Active learning works for while loops because students must physically trace how conditions change with each pass, turning abstract logic into observable behavior. When students pair up or move in small groups, they verbalize their thinking and catch errors in real time, which builds lasting understanding of termination conditions. The hands-on nature of these activities makes infinite loops feel tangible rather than theoretical.

MOE Syllabus OutcomesMOE: Programming - S3
20–40 minPairs → Whole Class4 activities

Activity 01

Stations Rotation30 min · Pairs

Pair Programming: Number Guessing Game

Pairs write a while loop for a guessing game where the computer picks a number from 1-100 and prompts guesses until correct. Include hints like 'too high' or 'too low'. Test with 5-10 rounds and count attempts.

Differentiate between 'for' loops and 'while' loops and when to use each.

Facilitation TipDuring Pair Programming, circulate to ensure pairs print the loop variable inside the loop to visualize how the condition evolves.

What to look forProvide students with a short Python code snippet containing a 'while' loop. Ask them to: 1. Trace the execution and state the final output. 2. Identify the loop's condition and explain why it terminates (or why it might not).

RememberUnderstandApplyAnalyzeSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 02

Stations Rotation40 min · Small Groups

Small Groups: Input Validator

Groups create a program using while loops to repeatedly ask for age input until between 13-18. Add a counter for attempts and exit message. Share and demo one valid, one invalid input sequence.

Design a 'while' loop that correctly terminates based on user input.

Facilitation TipFor the Input Validator activity, ask groups to write down the exact moment their loop should stop and the condition that will trigger it.

What to look forPresent students with two scenarios: Scenario A: 'Print numbers from 1 to 10.' Scenario B: 'Keep asking the user for a password until they enter the correct one.' Ask them to choose which scenario is better suited for a 'for' loop and which for a 'while' loop, and briefly justify their choices.

RememberUnderstandApplyAnalyzeSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 03

Stations Rotation25 min · Whole Class

Whole Class: Infinite Loop Hunt

Display 5 code snippets with while loops on the board. Class votes on which run infinitely, then runs them in Python to verify. Discuss fixes like incrementing counters.

Analyze potential issues like infinite loops and how to prevent them.

Facilitation TipWhen running the Infinite Loop Hunt, pause the class to discuss each example and vote on whether the loop will stop or run forever.

What to look forPose the question: 'Imagine you are writing a program to guess a number between 1 and 100. You want the user to input their guess, and the program tells them 'higher' or 'lower' until they guess correctly. What are the key components of the 'while' loop you would need to design for this game, and what potential problems must you avoid?'

RememberUnderstandApplyAnalyzeSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 04

Stations Rotation20 min · Individual

Individual: Loop Modifier

Students modify a given while loop summing numbers until user enters zero, adding input checks for non-numbers. Run tests with sample inputs and log results.

Differentiate between 'for' loops and 'while' loops and when to use each.

Facilitation TipFor Loop Modifier, provide a starter code snippet with a missing update and ask students to trace where the variable changes.

What to look forProvide students with a short Python code snippet containing a 'while' loop. Ask them to: 1. Trace the execution and state the final output. 2. Identify the loop's condition and explain why it terminates (or why it might not).

RememberUnderstandApplyAnalyzeSelf-ManagementRelationship Skills
Generate Complete Lesson

A few notes on teaching this unit

Teach while loops by starting with scenarios where students cannot know the number of repeats in advance, such as user input validation. Use live tracing with print statements inside the loop to make the condition’s behavior visible and concrete. Emphasize variable updates early, as research shows this is the most common source of confusion. Avoid rushing to abstract explanations before students have felt the loop run multiple times with real data.

Students will confidently distinguish while loops from for loops and justify their choices with clear reasons. They will write while loops that update variables to avoid infinite loops and explain why termination matters. Peer discussions and live debugging will show that they notice missing updates and misplaced conditions.


Watch Out for These Misconceptions

  • During Pair Programming: Number Guessing Game, watch for students who forget to update the guess count or the target range inside the loop.

    Ask each pair to add a print statement after each guess that displays the current guess count and the loop condition’s state. Have them trace how the loop ends only when the condition becomes false due to updates.

  • During Small Groups: Input Validator, watch for students who treat the while loop like a for loop with a fixed range.

    Provide a scenario where the valid input cannot be predicted in advance, such as a password that could be any length or combination. Ask groups to explain why their loop must keep running until a specific signal is received, not until a counter hits a number.

  • During Whole Class: Infinite Loop Hunt, watch for students who believe the loop checks its condition after running the code block.

    During the hunt, run each example step-by-step with the class, inserting print statements before and after the condition check. Ask students to predict the next action based on the printed outputs.


Methods used in this brief