1#in Python, break statements can be used to break out of a loop
2for x in range(5):
3 print(x * 2)
4 if x > 3:
5 break
1number = 0
2
3for number in range(10):
4 if number == 5:
5 break # break here
6
7 print('Number is ' + str(number))
8
9print('Out of loop')
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.')
1>>> for num in range(2, 10):
2... if num % 2 == 0:
3... print("Found an even number", num)
4... continue
5... print("Found a number", num)
6Found an even number 2
7Found a number 3
8Found an even number 4
9Found a number 5
10Found an even number 6
11Found a number 7
12Found an even number 8
13Found a number 9
14
1nums = [6,8,0,5,3]
2product = 1
3
4for num in nums:
5 if num == 0:
6 product = 0
7 break # stops the for loop
8 product *= num
9
10print(product)