1import numpy as np
2values=np.arange(0,10)
3for value in values:
4 if value==3:
5 continue
6 elif value==8:
7 print('Eight value')
8 elif value==9:
9 break
1## When the program execution reaches a continue statement,
2## the program execution immediately jumps back to the start
3## of the loop.
4while True:
5 print('Who are you?')
6 name = input()
7 if name != 'Joe':
8 continue
9 print('Hello, Joe. What is the password? (It is a fish.)')
10 password = input()
11 if password == 'swordfish':
12 break
13print('Access granted.')
1words = ["rain", "sun", "moon", "exit", "weather"]
2
3for word in words:
4 #checking for the breaking condition
5 if word == "exit" :
6 #if the condition is true, then break the loop
7 break;
8 if word == "moon" :
9 #this statement will be executed
10 print("moon is skipped")
11 continue
12 #this statement won't be executed
13 print ("This won't be printed")
14 #Otherwise, print the word
15 print (word)
1nums = [7,3,-1,8,-9]
2positive_nums = []
3
4for num in nums:
5 if num < 0: #skips to the next iteration
6 continue
7 positive_nums.append(num)
8
9print(positive_nums) # 7,3,8
1# Example of continue loop:
2
3for number is range (0,5):
4 # If the number is 4, skip the rest of the loop and continue from the top.
5 if number == 4:
6 continue
7
8 print(f"Number is: {number}")