Member-only story
Loops in Python {1}
4 min readDec 13, 2024
Hello,
Press enter or click to view image in full size![]()
1. Basic for Loop
pythonCopy codefor i in range(5):
print(i) # 0, 1, 2, 3, 42. for Loop with List
pythonCopy codefruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)3. for Loop with Index (enumerate)
pythonCopy codefruits = ["apple", "banana", "cherry"]
for index, fruit in enumerate(fruits):
print(f"{index}: {fruit}")4. Nested for Loop
pythonCopy codefor i in range(3):
for j in range(3):
print(f"i={i}, j={j}")5. for Loop with break
pythonCopy codefor i in range(10):
if i == 5:
break
print(i) # Stops at 46. for Loop with continue
pythonCopy codefor i in range(10):
if i % 2 == 0:
continue
print(i) # Prints odd numbers





