Step-by-Step Execution
range(3) → means the loop will normally run for i = 0, 1, 2.
-
First iteration:
-
i = 0
print(i) → prints 0
if i == 1: → condition False, so it continues.
-
Second iteration:
-
i = 1
print(i) → prints 1
if i == 1: → condition True
-
Executes break → this stops the loop immediately.
-
Because the loop is terminated using break,
the else block is skipped.
Output
Key Concept
In Python,
for...else and while...else blocks work like this:
-
The else part runs only if the loop completes normally (no break).
-
If a break statement is used, the else block will not execute.
Try Changing It
If you remove the break, like this:
Then output will be:

.png)

.jpg)
.png)



.png)
.png)



.png)

