+ 1

In the continue Loop - i = 0 while True: i = i +1 if i == 2: print("Skipping 2") continue if i == 5: print("Breaking") break print(i) print("Finished") It shows the output being "1 Skipping 2 3 4 Breaking Finished" Why are the last three lines not "Breaking 5 Finished" Where it shows print(i) after break?

clarification please?

3rd Oct 2016, 11:10 PM
Adam Atkinson
Adam Atkinson - avatar
3 Réponses
+ 3
"break" breaks the loop immediately even if "break" is inside "if/elif/else". You just exit the loop if you encounter "break". "print(i)" is inside the loop so it is not executed (you have exited the loop)
3rd Oct 2016, 11:45 PM
novice
0
Ohhh right. That actually helped a lot. Thank you
3rd Oct 2016, 11:57 PM
Adam Atkinson
Adam Atkinson - avatar
0
please explain the whole code..I m not getting it..as u said continue will ignores the next statement and will go to the top of loop..so how it is printing 1
9th Jan 2017, 12:24 PM
Pragya Priya
Pragya Priya - avatar