+ 12

What is the difference between break and continue?

16th Feb 2018, 5:16 PM
A͢J
A͢J - avatar
4 Respuestas
+ 4
'break' will break out of your current loop such as for and while loop. Then execute statement after that loop. Eg. for i in [1,2,3,4]: print(i) if i == 2: break print('End of loop') output >> 1 End of loop In my 'python' code, for loop itetate list given. When i equal 2 then it will break out of current loop (i.e for loop) and execute print function. 'continue' is opposite. It goes back to loop when use. So, if i use continue instead of break in above code, output will be: 1 2 3 4 End of loop That's it! Although programming syntax may be different, fundamental knowledge are the same. Hope it helps :)
16th Feb 2018, 5:30 PM
Sylar
+ 3
https://code.sololearn.com/ccxweEAFB4Bv/?ref=app break stops loop. Continue skips loop on given condition. Here, when i got to 2, it continued loop, skipped that part. When i got to 13, break stopped the loop. Hope I helped you
16th Feb 2018, 5:24 PM
Sad
Sad - avatar
+ 2
break stops the loop and exits from it, while continue skips the current condition and continues the loop for the next conditions
25th May 2018, 10:07 AM
Yaseen Abdalla Ibrahim Alsafi
Yaseen Abdalla Ibrahim Alsafi - avatar