Explanation:
1. range(10, 0, -2):
This creates a sequence starting from 10, going down by 2 each time, stopping before it reaches 0.
So the values of i will be:
2. if i < 5: break:
-
The loop will stop immediately if i becomes less than 5.
break exits the loop completely.
3. print(i):
-
It only prints the value of i if the loop hasn't been broken.
🔁 Execution Flow:
| Value of i | Condition i < 5 | Action |
|---|---|---|
| 10 | False | print(10) |
| 8 | False | print(8) |
| 6 | False | print(6) |
| 4 | True | break (stop) |
| 2 | not executed | loop ended |


0 Comments:
Post a Comment