what is different between break and continue) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

what is different between break and continue)

13th Feb 2021, 8:47 PM
Nourhan selim abdo
Nourhan selim abdo - avatar
4 Answers
+ 6
Break is used to exit the loop while continue is used to skip to the next iteration.
13th Feb 2021, 8:53 PM
Sonic
Sonic - avatar
+ 6
The tutorials here explain this.
13th Feb 2021, 8:52 PM
Sonic
Sonic - avatar
+ 2
number = 0 for number in range(10): if number == 5: break # break here print('Number is ' + str(number)) --- output --- Number is 0 Number is 1 Number is 2 Number is 3 Number is 4 ------------------------------------------------------------------------ number = 0 for number in range(10): if number == 5: continue # continue here print('Number is ' + str(number)) --- output --- Number is 0 Number is 1 Number is 2 Number is 3 Number is 4 Number is 6 Number is 7 Number is 8 Number is 9
13th Feb 2021, 9:23 PM
Jamal Saied
Jamal Saied - avatar
+ 1
Break is used to get out of the loop .... continue doesn't skip elements understand this ..... If you write print () below continue then it. Will work ....but if you put print() above continue then it will not skip element. Basically continue take the pointer return to the first line of loop .....so whatever rests below continue statement it will not executed because pointer goes to first line of the loop after continue ....so automatically it will be skipped . I hope this will help you to understand difference.
14th Feb 2021, 5:19 PM
Hemant Kosrekar
Hemant Kosrekar - avatar