Step-by-Step Execution
-
Initialize i = 0
-
The loop starts with i = 0.
-
-
Condition check → i < 3
-
Since 0 < 3, the loop runs.
-
-
Inside loop → i += 1
i becomes 1.
-
Next iteration
-
Check again: 1 < 3 → True → run loop → i = 2.
-
-
Next iteration
-
Check: 2 < 3 → True → run loop → i = 3.
-
-
Next check
3 < 3 → False → loop stops.
else block executes
-
The else part runs only if the loop exits normally (not via break).
-
-
Output
Done
๐ง Key Concept
-
The else clause with a while loop runs after the loop finishes normally.
-
If the loop is terminated using break, the else part is skipped.
✅ Final Output:
Done


0 Comments:
Post a Comment