Let's break it down simply
A Python for loop steps through the items of a sequence or iterable one by one. Use range() when you want to repeat a fixed number of times, and while when you want to keep going as long as a condition holds. break stops the loop entirely, while continue skips to the next iteration.
python
scores = [68, 42, 91, 77]
for index, score in enumerate(scores, start=1):
if score < 50:
continue
print(f"{index}: {score}")
attempts = 3
while attempts > 0:
print(f"Attempts left: {attempts}")
attempts -= 1You should see
1: 68
3: 91
4: 77
Attempts left: 3
Attempts left: 2
Attempts left: 1Try it yourself
Write a loop from 1 to 30 that prints Fizz for multiples of 3 and Buzz for multiples of 5.
Python Control Flow — Python Software Foundation