python stop while loop 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: python stop while loop after time
import time
timeout = time.time() + 60*5
while True:
test = 0
if test == 5 or time.time() > timeout:
break
test = test - 1