how to end a loop when a certain condition is met code example
Example 1: 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 2: how to skip number in while loop python
def skip_down(num, skip):
count = 0
lst = [0]
while count< num:
count = count + skip
lst.append(count)
return lst
print(skip_down(10, 3))