Step 1: Understand range(3)
range(3) → 0, 1, 2So the loop runs with i = 0, then 1, then 2.
๐น Step 2: Loop execution
| i | Condition i > 1 | Action |
|---|---|---|
| 0 | False | Go to else → print(0) |
| 1 | False | Go to else → print(1) |
| 2 | True | continue → skip print |
๐น What continue does
continue skips the rest of the loop body and jumps to the next iteration.
So when i == 2, continue is executed → print(i) is skipped.
✅ Final Output
๐น Key Points
else runs only when if condition is False.
continue skips the remaining code in the loop for that iteration.
-
So 2 is never printed.
In one line:
This code prints all values of i less than or equal to 1 and skips values greater than 1.


0 Comments:
Post a Comment