Python continue Statement In Hindi

📔 : Python 🔗

Python में continue का use किसी दी गयी condition के according current loop iteration को skip करने के लिए किया जाता है। और skip करने के बाद Loop next iteration से Start हो जाता है। simply हम कह सकते हैं कि Python में continue का use हम वहाँ करते हैं जब हमें किसी condition पर loop execution को skip करना हो।

Python continue Example

Copy Fullscreen Close Fullscreen Run
for no in range(1, 10) :
	if(no == 5) :
		continue;
	print(no)
Output
C:\Users\Rahulkumar\Desktop\python>python continue_ex.py
1
2
3
4
6
7
8
9

Example अगर आप देखेंग तो 5 print ही नहीं हुआ है because जैसे ही no की value 5 होगी वो iteration skip हो जायगी और next iteration start हो जाती है।

? well , Python में continue statement PHP से थोड़ा अलग होता है क्योंकि PHP continue statement में optional parameter की value दे सकते हैं जैसे - continue 2 ; . जिसका मतलब हम हम दो Loop (inner , outer) एक साथ skip कर रहे हैं।

लेकिन Python में ऐसा नहीं है , Python में कोई optional parameter pass नहीं होता है , यह सिर्फ एक ही Loop की iteration skip होती है।


ऐसा नहीं कि continue को आप सिर्फ for loop के साथ ही use कर सकते हैं , आप इसे while loop या किसी भी loop statement के साथ use कर सकते हैं।

Python continue with while Loop

Copy Fullscreen Close Fullscreen Run
no = 0
while no < 10 :
   no = no+1
   if(no == 5) :
      continue;
   print(no);
Output
C:\Users\Rahulkumar\Desktop\python>python continue_while.py
1
2
3
4
6
7
8
9
10

I Hope, अब आप समझ गए होंगे कि continue को क्यों ,कैसे और कहाँ use कर सकते हैं।

Remember

जब आप continue loop के साथ use कर रहें हों तो कुछ बातें हमेशा याद रखें।


1. अगर आप while loop में continue use कर रहें हैं , तो जिस variable increment / decrement कर रहें हों उसे हमेशा continue statement वाली line से पहले ही modify करें। variable को बाद में न लिखें।

#not valid
if(no == 5) :
   continue;
no = no+1

क्योंकि यहां पर जैसे ही condition True होगी बैसे ही current iteration skip हो जायगी। लेकिन जब next iteration run होगी तो फिर से variable की value same ही मिलेगी because variable में increment / decrement statement तो नीचे लिखा है। इसलिए loop endlessly skip करता रहेगा।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers