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")

6th Jun 2017, 6:10 AM
Nipun Grover
Nipun Grover - avatar
2 Respostas
0
result: >>> 1 Skipping 2 3 4 Breaking Finished >>>
6th Jun 2017, 6:11 AM
Nipun Grover
Nipun Grover - avatar
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.
9th Jun 2017, 9:40 AM
Bogdan Sass
Bogdan Sass - avatar