Python Break
Break statement
The Break statement is used in statements like for or while loop. If the condition is met, then you can use break statement to exit the loop.
Examples
>>> for n in range(1, 5): for x in range (3, n): if x == 4: print('Value of n is ',n) break else: print('No x value') No x value >>>
>>> list(range(0,5)) [0, 1, 2, 3, 4] >>> a = 3 >>> for x in range(0,5): for y in range(0,x): if a==3: print('value: ',x) break else: print('a is not 3') value: 1 value: 2 value: 3 value: 4 >>>