Python Loop else: Normal Completion and break
5 flashcards · 4 quiz questions · 5 match pairs · 4 fill-in sentences · English
Your progress is kept in this browser only.Sign up to save it
Summary
A loop can finish in two different ways: it can complete all its iterations normally, or it can be interrupted by a break statement. Python’s loop else clause helps distinguish these outcomes.
The else clause belongs to the loop, not to an if statement inside it. It runs when the loop finishes normally—that is, when a for loop has no more items to process or a while loop’s condition becomes false. If the loop exits because it executes break, the loop’s else clause is skipped.
All flashcards
Quiz questions
Based on Introduction to Python Programming by Udayan Das, Aubrey Lawson, Chris Mayfield, Narges Norouzi (OpenStax), licensed CC BY 4.0. Adapted into a summary, flashcards and quizzes.