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


Picture showing the output of for-else statements in python



Posted By  -  Karan Gupta
 
Posted On  -  Friday, September 10, 2021

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250