Articles → PYTHON → For-Else Statements In Python
For-Else Statements In Python
Purpose
Example
count = 4
for i in range(0, count):
print(i)
else:
print("for loop ended")
# Loop breaks in between
count = 4
for i in range(0, count):
if i == 2:
break
print(i)
else:
print("for loop ended")
Output