4. While else
A while loop can have an else block:
The else block runs once, when the loop ends because the condition became False. It does not run when the loop ends with break.
That makes else useful for searches: put the "not found" message in else, and break when the item is found.
Print after the loop ends
Use a counter n starting at 0. While n is less than 3, print n and add 1. Add an else that prints Done.
Print exactly:
Create a free account to save your progress and unlock chapter 2.
Else is skipped by break
Start n at 0. While n is less than 3, print n, add 1, and break when n becomes 2. Add an else that prints Done. Because the loop ends with break, Done must not appear.
Print exactly:
Create a free account to save your progress and unlock chapter 2.
Search with while else
Start n at 2. While n is less than 35, break and print First divisor: <n> when 35 % n == 0; otherwise add 1 to n. Add an else that prints No divisor.
Print exactly:
Create a free account to save your progress and unlock chapter 2.