For loop and while loop
For loop and while loop
🔹 1. For Loop
✅ Syntax:
python
CopyEdit
for variable in sequence:
# code block
python
CopyEdit
for i in range(5):
print(i)
# Output: 0 1 2 3 4
python
CopyEdit
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
🔹 2. While Loop
✅ Syntax:
python
CopyEdit
while condition:
# code block
✅ Example:
python
CopyEdit
count = 0
while count < 5:
print(count)
count += 1
# Output: 0 1 2 3 4
🔸 Loop Control Statements
Statement Description
break Exits the loop immediately
continue Skips the current iteration
pass Does nothing (placeholder)
python
CopyEdit
for i in range(5):
if i == 3:
break
print(i)
# Output: 0 1 2
python
CopyEdit
for i in range(5):
if i == 3:
continue
print(i)
# Output: 0 1 2 4
Let me know if you'd like this content converted into a downloadable PDF once the tools are
working again.