- Introduction to break statement in python in Hindi

Contents
show
Introduction to break statement in Python
ब्रेक python में एक कीवर्ड है जिसका उपयोग प्रोग्राम नियंत्रण को लूप से बाहर लाने के लिए किया जाता है। ब्रेक स्टेटमेंट एक-एक करके loops को तोड़ता है, यानी नेस्टेड लूप्स के मामले में, यह पहले आंतरिक लूप को तोड़ता है और फिर बाहरी loops को। दूसरे शब्दों में, हम कह सकते हैं कि ब्रेक का उपयोग प्रोग्राम के वर्तमान निष्पादन को रोकने के लिए किया जाता है और नियंत्रण लूप के बाद अगली line में जाता है।
ब्रेक आमतौर पर उन मामलों में उपयोग किया जाता है जहां हमें किसी दिए गए शर्त के लिए लूप को तोड़ने की आवश्यकता होती है।
ब्रेक का सिंटैक्स नीचे दिया गया है।
#loop statements
break;
उदाहरण 1
list =[1,2,3,4]
count = 1;
for i in list:
if i == 4:
print("item matched")
count = count + 1;
break
print("found at",count,"location");
आउटपुट:
item matched found at 2 location
उदाहरण 2
str = "python"
for i in str:
if i == 'o':
break
print(i);
आउटपुट:
p y t h
उदाहरण 3: लूप के साथ स्टेटमेंट को तोड़ें
i = 0;
while 1:
print(i," ",end=""),
i=i+1;
if i == 10:
break;
print("came out of while loop");
आउटपुट:
0 1 2 3 4 5 6 7 8 9 came out of while loop