5.11 Loop else¶
Loop else construct¶
- A loop may optionally include an else clause that executes only if the loop terminates normally, not using a break statement.
The complete forms of while and for loops are:
- The loop else construct executes if the loop completes normally.
- Example: a special message "All names printed" is displayed if the entire list of names is completely iterated through: