Learning Objective
At the end of the lesson you will understand Python's for and while loops, write your own loop programs, and solve basic problems using loops
Learning Objective
At the end of the lesson you will understand Python's for and while loops, write your own loop programs, and solve basic problems using loops
What do you already know about loops in Python?
What Are Loops in Programming?
Loops help us repeat a set of instructions, saving time and making our code shorter and clearer.
For Loops: Structure & Syntax
A for loop repeats over a range or list. Example: for i in range(1, 6): print(i)
While Loops: Structure & Syntax
A while loop repeats while a condition is true. Example: count = 1 while count <= 5: print(count) count += 1
Comparing For and While Loops
Use when you do not know how many repetitions in advance. Great for repeating until a condition changes.
Use when the number of repetitions is known. Excellent for iterating over lists or ranges.
For Loops
While Loops
Loop Problem-Solving Challenge
Pick an index card, choose the right loop for the problem, and solve it in Python. Share your solution with the class.
Reflection & Discussion
How do loops make programming easier? When might you choose a for loop versus a while loop? Share your thoughts.
Write down 3 things you learned in this lesson.
Write down 2 things you want to know more about.
Ask 1 question about something you haven't quite understood yet.