Infinite Loops
The Python programming language doesn’t have a dedicated construct for infinite loops, but it’s easy enough to create a while loop that runs forever.
Dependencies
Students need to have these skills before learning this skill:
Goal
When you teach this skill, your goal is to make it so that students can write code that looks like this:
while True:
name = input("Enter you name: ")
print("You are")
print(name)
Activities
Here are some activities that you can do in order to teach this skill.
Writing on the board
-
Write this code on the board:
while True:
favorite_color = input("What is your favorite color? ") -
Ask students what they think that code is going to do.
-
Run the code and show students what it actually does.
-
Explain to students why the code does what it does.