Answers for "python break out of function"

4

python exit loop iteration

alphabet = ['a' , 'b' , 'c' , 'd' ]
for letter in alphabet:
  if letter == 'b' :
    continue
    #continues to next iteration
  print( letter )
for letter in alphabet:
  if letter == 'b' :
    break
    #terminates current loop
  print( letter )
for letter in alphabet:
  if letter == 'b' :
    pass
    #does nothing
  print( letter )
Posted by: Guest on April-06-2020
7

python break

nums = [6,8,0,5,3]
product = 1

for num in nums:
  if num == 0:
    product = 0
    break # stops the for loop
  product *= num

print(product)
Posted by: Guest on May-27-2020
0

python break out of function

def function():
    return # breaks out of a function
    print('This does not happen')
Posted by: Guest on August-09-2021
-2

break function python

if( x > 3):
  print('X is greater than 3')
else:
  break
Posted by: Guest on June-21-2020

Python Answers by Framework

Browse Popular Code Answers by Language