Explanation:
-
Initialization:
-
A variable i is created and set to 0.
-
-
While Loop:
-
This loop runs as long as i is less than 10.
-
-
If Condition with Break:
-
Each time through the loop, Python checks:
๐ "Is i equal to 7?"-
If yes, the break statement stops the loop immediately.
-
-
-
Increment:
-
If i is not 7, i is increased by 1.
-
๐ What Happens in Each Iteration:
| Iteration | i value before check | i == 7? | Action | i after increment | ||
|---|---|---|---|---|---|---|
| 1 | 0 | No |
| 1 | ||
| 2 | 1 | No | i += 1 | 2 | ||
| 3 | 2 | No | i += 1 | 3 | ||
| 4 | 3 | No | i += 1 | 4 | ||
| 5 | 4 | No | i += 1 | 5 | ||
| 6 | 5 | No | i += 1 | 6 | ||
| 7 | 6 | No | i += 1 | 7 | ||
| 8 | 7 | Yes | break | (loop stops here) |
Final Output:
-
The last value of i before breaking was 7, so 7 is printed.
✅ Output:


0 Comments:
Post a Comment