+ 3

What's the difference between break and continue statements?

Hey, I was writing a program in python 3 and it wasn't working until I realized that the break statements were forcing the program to leave the for loop. So I think I'm a little confused between what continue statements versus break statements do. Can anyone help clarify?

4th Jul 2017, 7:10 PM
Ava Nicole
Ava Nicole - avatar
11 Answers
+ 3
Short answer: Break means that the loop ends. Continue means to stop and go back to the begging of the loop executing the next iteration. Long answer with example: n = 1 x = 0 while True: if n > x: break else: print('hello') This example the loop stops completely and never executes 'hello' because n(1) is greater than x(0) n = 1 x = 0 while True: if n > x: continue else: print('hello') In this example the program does not executes 'hello' because n(1) is greater than x(0) HOWEVER the loop does not stop it just go back to the beginning and continues the loop. In this example the loop never stops it is infinite. Not useful program just did it to illustrate what break and continues does.
4th Jul 2017, 7:25 PM
Code101
Code101 - avatar
+ 2
You can reach out to me here it's fine. What's up?
5th Jul 2017, 6:03 AM
Ava Nicole
Ava Nicole - avatar
0
Awesome thanks for clearing that up
4th Jul 2017, 7:50 PM
Ava Nicole
Ava Nicole - avatar
0
Hey ava, is there any to contact you, i am having problems in phyton,
5th Jul 2017, 5:51 AM
Ranabir Ghosh
Ranabir Ghosh - avatar
0
Ok. Can you tell me what is the problem here, i=1 While i<=1: Print (i) I=i+1 Print ("Finished")
5th Jul 2017, 6:07 AM
Ranabir Ghosh
Ranabir Ghosh - avatar
0
It says syntax error
5th Jul 2017, 6:08 AM
Ranabir Ghosh
Ranabir Ghosh - avatar
0
And tell me how do I run the program, after writing print. What to do
5th Jul 2017, 6:08 AM
Ranabir Ghosh
Ranabir Ghosh - avatar
5th Jul 2017, 6:13 AM
Ranabir Ghosh
Ranabir Ghosh - avatar
0
lol
5th Jul 2017, 10:02 AM
Code101
Code101 - avatar
0
You're while and print statements need to be lowercase in order for the code to work
5th Jul 2017, 9:54 PM
Ava Nicole
Ava Nicole - avatar
0
Python is a case sensitive language
5th Jul 2017, 9:54 PM
Ava Nicole
Ava Nicole - avatar