Using else with Loops in Python


An else block after a loop executes if the loop completes normally (no break).

Source Code

for i in range(3):
    print(i)
else:
    print("Loop finished!")
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments