In programming, you often need to repeat actions — like checking a list, asking a question multiple times, or counting through numbers. Instead of writing the same code again and again, you can use a loop. Python has two main types: for loops and while loops. Each has a different purpose, and learning both will help you write cleaner, smarter code.
For Loops
A for loop is used when you know exactly how many times you want to repeat something. It’s great for going through lists or repeating a block of code a set number of times. You’ll learn how to use range() to control your loops and how to access each item in a list using a loop.
While Loops
A while loop keeps running as long as a condition is true. It’s useful when you don’t know how many times something should repeat — like asking for input until the user types a specific word. You’ll practise creating while loops with clear conditions so your program doesn’t get stuck in an infinite loop.