New: Complete Beginner's Guide to Coding is now available in Premium
Updated: Indian Govt Exam roadmaps now include salary breakdowns & timelines
Tip: Use the Career Hub to explore all career paths in one place
Tutorials Python Python Loops

Python Loops

Python

Loops let you repeat code. Python has two main loops: for and while.

Key Points

  • for loop — iterate over a sequence (list, range, string)
  • while loop — repeat as long as a condition is true
  • break — exit the loop early
  • continue — skip current iteration
  • range(start, stop, step) — generates numbers
Example — PYTHON
# For loop with range
for i in range(1, 6):
    print(f"Count: {i}")
# Loop through a list
fruits = ["Mango", "Banana", "Apple"]
for fruit in fruits:
    print(f"I like {fruit}")
# While loop
num = 1
while num <= 5:
    print(f"Number: {num}")
    num += 1
# Break and Continue
for i in range(1, 11):
    if i == 5:
        break
    if i % 2 == 0:
        continue
    print(i)
# Multiplication table
n = 7
for i in range(1, 11):
    print(f"{n} x {i} = {n * i}")
Result
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
I like Mango
I like Banana
I like Apple
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
1
3
7 x 1 = 7
7 x 2 = 14
... (up to 7 x 10 = 70)