Break Continue and Pass in Python
Break Continue and Pass in Python
• def display(number):
•
• if number is 2:
• pass # Pass statement
• else:
• print ("Number: ", number)
•
• display(2)
• display(3)
•Examples
The working example using break
statement is as shown below:
• my_list = ['Siya', 'Tiya', 'Guru', 'Daksh', 'Riya', 'Guru']
• for i in range(len(my_list)):
• print(my_list[i])
• if my_list[i] == 'Guru':
• print('Found the name Guru')
• break
• print('After break statement')
• print('Loop is Terminated')
Example: Break statement inside while-loop
• for i in range(4):
• for j in range(4):
• if j==2:
• break
• print("The number is ",i,j);
Example : Continue inside for-loop
• for i in range(10):
• if i == 7:
• continue
• print("The Number is :" , i)
Example : Continue inside while-loop
• i=0
• while i <= 10:
• if i == 7:
• i += 1
• continue
• print("The Number is :" , i)
• i += 1
Example: pass statement inside a function
• def my_func():
• print('pass inside function')
• pass
• my_func()