Explanation:
1. Initialization
i = 1
A variable i is created and assigned the value 1.
This will act as a counter for the loop.
while i < 5:
The loop will continue as long as i is less than 5.
Once i becomes 5 or greater, the loop stops.
3. If Condition (Break Statement)
if i == 3:
break
Inside the loop, Python checks if i is equal to 3.
If it is, the break statement immediately stops the loop — even if the while condition is still true.
print(i)
This prints the current value of i on the screen.
i += 1
This increases the value of i by 1 each time the loop runs.
Without this step, i would never change and the loop could run forever.
Final Output
1
2


0 Comments:
Post a Comment