break a loop in python code example
Example 1: python break for loop
#in Python, break statements can be used to break out of a loop
for x in range(5):
print(x * 2)
if x > 3:
break
Example 2: break python
# Use of break statement inside the loop
for val in "string":
if val == "i":
break
print(val)
print("The end")
---------------------------------------------------------------------------
s
t
r
The end
Example 3: break function python
if( x > 3):
print('X is greater than 3')
else:
break