Python Tutorial in Hindi #12 - For Loop

For Loop in Python – Learn how to iterate through lists, strings, and more with Python’s for loop!


In this video by Mohit Decodes, we cover:

✅ How for loop works in Python

✅ Syntax and flow of for loop

✅ Using break to exit early

✅ Using continue to skip iterations

✅ What is pass and when to use it

✅ Practical code examples for each


🧩 Example 1: Basic For Loop
# Basic For Loop Example
for i in range(5):
print("Mohit Decodes", i)


Output:

Mohit Decodes 0
Mohit Decodes 1
Mohit Decodes 2
Mohit Decodes 3
Mohit Decodes 4

🧩 Example 2: Iterating a List
# Iterating a list using for loop
fruits = ["apple", "banana", "mango"]
for fruit in fruits:
print(fruit)


Output:

apple
banana
mango

🧩 Example 3: Iterating a String
# Iterating over a string
for ch in "Python":
print(ch)


Output:

P
y
t
h
o
n

🧩 Example 4: Using range(start, end, step)
# Using range() with start, end, and step
for num in range(2, 11, 2):
print(num)


Output:

2
4
6
8
10

🧩 Example 5: Using break in For Loop
# break example
for i in range(1, 11):
if i == 5:
break
print(i)
print("Loop ended at i =", i)


Output:

1
2
3
4
Loop ended at i = 5

🧩 Example 6: Using continue in For Loop
# continue example
for i in range(1, 6):
if i == 3:
continue
print(i)


Output:

1
2
4
5

🧩 Example 7: Using pass in For Loop
# pass statement example
for i in range(5):
if i == 2:
pass # placeholder, does nothing
print("i =", i)


Output:

i = 0
i = 1
i = 2
i = 3
i = 4

🧩 Example 8: Nested For Loop
# Nested For Loop example
for i in range(1, 4):
for j in range(1, 4):
print(i, "*", j, "=", i * j)
print("-----")


Output:

1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
-----
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
-----
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
-----