continue example in python
Example 1: continue statement python
import numpy as np
values=np.arange(0,10)
for value in values:
if value==3:
continue
elif value==8:
print('Eight value')
elif value==9:
break
Example 2: python while continue
while True:
print('Who are you?')
name = input()
if name != 'Joe':
continue
print('Hello, Joe. What is the password? (It is a fish.)')
password = input()
if password == 'swordfish':
break
print('Access granted.')
Example 3: python for continue
>>> for num in range(2, 10):
... if num % 2 == 0:
... print("Found an even number", num)
... continue
... print("Found a number", num)
Found an even number 2
Found a number 3
Found an even number 4
Found a number 5
Found an even number 6
Found a number 7
Found an even number 8
Found a number 9
Example 4: python continue
nums = [7,3,-1,8,-9]
positive_nums = []
for num in nums:
if num < 0:
continue
positive_nums.append(num)
print(positive_nums)
Example 5: continue in python
for number is range (0,5):
if number == 4:
continue
print(f"Number is: {number}")