Plenty of π
Module 3: Control Flow - Conditional Execution and Loops
Loops: `while` and `for`

Loops are used to repeat a block of code multiple times.

  • while loop: Repeats a block of code as long as a condition is True. count = 0 while count < 5: print(count) count += 1 Be careful to avoid infinite loops by ensuring the condition eventually becomes False.

  • for loop: Iterates over a sequence (like a list, string, or range) or other iterable objects. for letter in "Python": print(letter) for i in range(5): print(i) # Prints 0, 1, 2, 3, 4 The range() function is commonly used with for loops to iterate a specific number of times. range(start, stop, step) generates numbers from start up to (but not including) stop, incrementing by step. If start is omitted, it defaults to 0. If step is omitted, it defaults to 1.