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# Use of break statement inside the loop
2
3for val in "string":
4 if val == "i":
5 break
6 print(val)
7
8print("The end")
9---------------------------------------------------------------------------
10s
11t
12r
13The end
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)