๐น Step 1: Understanding range(4)
range(4) → generates numbers from 0 to 3
So the loop runs with i = 0, 1, 2, 3
๐น Step 2: The if condition
This means:
➡️ If i is 1 or 3, the loop will skip the rest of the code (print) and move to the next iteration.
๐น Step 3: The print statement
print(i, end=" ") only runs when the if condition is False.
Let’s see what happens at each step:
| i | Condition (i==1 or i==3) | Action | Output |
|---|---|---|---|
| 0 | False | Printed | 0 |
| 1 | True | Skipped | |
| 2 | False | Printed | 2 |
| 3 | True | Skipped |
✅ Final Output
0 2Explanation in short
continue skips printing for i = 1 and i = 3
-
Only i = 0 and i = 2 are printed
Hence, output → 0 2


0 Comments:
Post a Comment