Python break statement

In python break statement is used if we want to exit out of loop when external condition is triggered. You out break statement with code under loop statement. The break statements terminate the current loop and resume execution at next statement like in c language. The common use for break statement is when some external condition triggered and required to exit from loop. Break is used in both while and for loop.
The need is used to stop /end the execution for a loop and the control of program goes to statement after last statement of loop. If the optional else statement is present in while/for loop skips the optional clause. The break statement is not nested in function or class within the loop. It terminates nearest loop, skips optional else clause if there is present. In simple language break keyword used to bring program control out of the loop. The break statement break loop one by one, as inner loop first and then outer loops.

Syntax:-

#loop statement
break

Flowchart:-
python break statement


Example:-
 str = "hello"  
 for i in str:  
 if i == 'o':  
 break  
 print(i);  

O/p:-
h
e
l
l

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India