The python break statement is used to terminate the loop when a certain condition is met.
Python break Syntax:
break
Python break flow diagram:
Examples:
1. Terminate the loop when x value reaches 6:
for x in range(10,1,-2): if x==6: break print(x) else: print("else block") print(x)
output:
2. Terminate the loop when x value reaches 4:
x=[1,3,5,8] for data in x: if data==4: break print(data) else: print("loop success")
output: