While loops
Lesson details
Learning outcome
I can use iteration controlled by a condition to repeat sequences of code.
Key learning points
- Computer programs use iteration to repeat sequences of instructions.
- Iteration can be controlled by a condition that determines if the instructions should be repeated.
- In Python, condition-controlled iteration is implemented using the 'while' loop command.
Keywords
Iteration - the process of repeating a sequence of instructions within a program loop
Condition - an expression that evaluates to True or False
Common misconception
A loop will always run at least once.
A loop only runs if the condition allows it. If the condition isn’t met initially, the code inside won’t run at all.
Teacher tip
Demonstrate a loop with a condition that is False from the start and ask students to predict the output. It helps pupils to develop their understanding regardless of if their prediction was correct or not.
Equipment
Pupils will need access to a device that can edit and run Python programs. Examples in this lesson use the RPF Code Editor https://oak.link/python-editor
Licence
Lesson video
Loading...
Prior knowledge starter quiz
6 Questions
Q1.What Python function is used to receive data that the user enters?
Q2.Which of these is a logical operator in Python?
Q3.What does the print function do?
Q4.What does the operator != mean?
Q5.What is the purpose of the if statement?
Q6.Match the examples to their descriptions.
True
whole number data type
decimal number data type
decision-making statement
Assessment exit quiz
6 Questions
Q1.What Python command is used for condition-controlled iteration?
Q2.What is iteration in programming?
Q3.What does a condition in a while loop do?
Q4.What happens if the condition in a while loop is False initially?
Q5.Order the steps of a condition-controlled loop.
Q6.Write the code to create iteration that will run if the variable num is over 5.
To help you plan your 10 computer science lesson on: While loops, download all teaching resources for free and adapt to suit your pupils' needs...
To help you plan your 10 computer science lesson on: While loops, download all teaching resources for free and adapt to suit your pupils' needs.
The starter quiz will activate and check your pupils' prior knowledge, with versions available both with and without answers in PDF format.
We use learning cycles to break down learning into key concepts or ideas linked to the learning outcome. Each learning cycle features explanations with checks for understanding and practice tasks with feedback. All of this is found in our slide decks, ready for you to download and edit. The practice tasks are also available as printable worksheets and some lessons have additional materials with extra material you might need for teaching the lesson.
The assessment exit quiz will test your pupils' understanding of the key learning points.
Our video is a tool for planning, showing how other teachers might teach the lesson, offering helpful tips, modelled explanations and inspiration for your own delivery in the classroom. Plus, you can set it as homework or revision for pupils and keep their learning on track by sharing an online pupil version of this lesson.
Explore more key stage 4 computer science lessons from the Programming: iteration unit, dive into the full secondary computer science curriculum, or learn more about lesson planning.