how to break out of while loop python code example
Example 1: infinite while python
while True:
print('Hello World!')
Example 2: python exit loop iteration
alphabet = ['a' , 'b' , 'c' , 'd' ]
for letter in alphabet:
if letter == 'b' :
continue
print( letter )
for letter in alphabet:
if letter == 'b' :
break
print( letter )
for letter in alphabet:
if letter == 'b' :
pass
print( letter )
Example 3: how to use try except in while loop in python
while True: try: num = int(input("Enter an int: ")) except Exception as e: print(e) else: print("Thank you for the integer!") break