0
Where is print(i) in the output and what it does mean?
i = 0 while True: i = i +1 if i == 2: print("Skipping 2") continue if i == 5: print("Breaking") break print(i) print("Finished")
2 Answers
0
result:
>>>
1
Skipping 2
3
4
Breaking
Finished
>>>
0
[Edited to clarify]
print(i) executes (as you can see) for i=1, i=3, and i=4.
For i=2, the "continue" statement triggers the next loop, skipping over the remaining code (including print(i)).
As for i=5, "break" throws you out of the current loop (in your case, the "while" loop), skipping over all remaining code in that loop. So print(i) doesn't execute for i=5, either.