Introduction
Break statement
It allows us to exit the loop at any point in condition. When a break statement encountered inside the loop then our loop terminates and our control jump out from the loop. For example, there is a list of numbers and you want to search a particular number inside the list, then you will start from the beginning and check each and every number with your search element, and if the search number found inside the list then you will never check further and break the loop.
Syntax:
- break;
Example 1:
Output:
- Names=["Sourabh Somani","DJ","Dinesh Beniwal","Abhishek Jaiswal"]
- Key=input("Please Enter the name which you want to search : ")
- i=1;
- for name in Names:
- if(Key==name):
- print(name," is found at ",i," Position in the List")
- break
- i+=1;
- else:
- print("Name is not present in the list")

Example 2
- #program to check
- #weather the given number is
- #prime number or not
- num = int(input("Enter a Number : "))
- for i in range(2,num):
- if(num%i==0):
- print("%d is not a prime number..."%num)
- break
- else:
- print("%d is a prime number..."%num)

Example 3:




Kapi ShivharePosted Nov 26, 2016, 7:30 AM
Good one thanks for sharing...
Santhakumar MunuswamyPosted Oct 18, 2015, 5:31 AM
Good one
Harshad PansuriyaPosted Oct 8, 2015, 4:24 AM
Nice one
Ankit BansalPosted Oct 8, 2015, 12:52 AM
nice one..
Nilesh JadavPosted Oct 7, 2015, 9:45 PM
Good One sir