000001 Lecture : Break Statement and Continue Statement in Python

8 views1 pages
20 Mar 2023
Department
Course
Professor

Document Summary

The break statement in python terminates the current loop and resumes execution at the next statement, just like the traditional break found in c. The most common use for break is when some external condition is triggered requiring a hasty exit from a loop. The break statement can be used in both while and for loops. Example: i=1 while (i<=10): if (i==5): break print (i) i=i+1 print ( successfully executed") The continue statement in python returns the control to the beginning of the while loop. The continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop. The continue statement can be used in both while and for loops. Eg: i=0 while (i<100): i=i+10 if (i==40): continue print (i) print ( successfully executed") o/p: