How To Use Break Statement in Pyhton

The break is a keyword in python , which can be used to bring the program control out of the loop i.e the execution or flow of program will stop or will jump to the next consecutive loops ( while and for ) or condition .

the break statement breaks the loops one by one , for example: in the case of nested loops,  it breaks the inner loop first and proceed to the outer loop

The 'break' is commonly used in the cases where we need to break the loop for a given condition

examples:

  • with break statement  

for i in range(10):      
     print("break me")       
      break                                                                                                                                        
  
   











  • without break statement 

for i in range(10): 
      print("breakme")
 

Comments