Step-by-Step Explanation:
1. Initialization
We start with n equal to 0.
2. while n < 4:
This loop runs as long as n is less than 4.
Loop Iterations:
| Iteration | n before print | n == 3? | continue? | print(n)? |
|---|---|---|---|---|
| 1 | 1 | ❌ No | ❌ No | ✅ Yes |
| 2 | 2 | ❌ No | ❌ No | ✅ Yes |
| 3 | 3 | ✅ Yes | ✅ Yes | ❌ Skipped |
| 4 | 4 | ❌ No | ❌ No | ✅ Yes |
What does continue do?
When n == 3, the line:
skips the print(n) line and jumps to the next iteration of the loop.
Final Output:
✅ Summary:
-
The loop runs 4 times (as n goes from 1 to 4).
-
It skips printing 3 because of the continue.


0 Comments:
Post a Comment