Important Notice:

The continue Statement

The continue Statement

20 views 2 min read

The continue Statement :-

continue Python का एक Loop Control Statement (लूप नियंत्रण कथन) है। इसका उपयोग loop की current iteration (वर्तमान दोहराव) को छोड़ने और loop की next iteration (अगले दोहराव) पर जाने के लिए किया जाता है।

जब Python को loop के अंदर continue statement मिलता है, तो उस iteration में continue के बाद लिखा हुआ code execute नहीं होता और loop सीधे अगली iteration पर चला जाता है।

English

The continue statement is a Loop Control Statement in Python. It is used to skip the current iteration of a loop and move to the next iteration.

When Python encounters a continue statement inside a loop, the remaining code of the current iteration is skipped, and the loop moves directly to the next iteration.

 

Syntax:-
 
continue

continue को हमेशा किसी for या while loop के अंदर लिखा जाता है।

Example:-
 
for i in range(1, 6):

    if i == 3:
        continue

    print(i)
 
Output:-
1
2
4
5
 
Because:-

range(1, 6) → 1, 2, 3, 4, 5

i = 1 → condition False → 1 print होगा।
i = 2 → condition False → 2 print होगा।
i = 3 → condition True → continue execute होगा।
इसलिए print(i) उस iteration में execute नहीं होगा।
Loop सीधे i = 4 पर चला जाएगा।
i = 4 → 4 print होगा।
i = 5 → 5 print होगा।

इसलिए output में 3 नहीं आएगा।

English

Here, the loop runs from 1 to 5.

When i = 3, the condition becomes True, so continue is executed. The print(i) statement is skipped for that iteration, and the loop moves to i = 4.

Therefore, 3 is not printed.

Another Example:-
 
#Odd Numbers को Skip करना -
 
for i in range(1, 11):

    if i % 2 != 0:
        continue

    print(i)
 
Output:-
2
4
6
8
10
 
Because:-

यहाँ i % 2 != 0 check करता है कि number odd है या नहीं।

यदि number odd है, तो continue उस iteration को skip कर देता है।

English

Here, i % 2 != 0 checks whether the number is odd.

If the number is odd, continue skips that iteration. Therefore, only even numbers are printed.

continue with while Loop :-

continue का उपयोग while loop में भी किया जा सकता है।

Example:-
 
i = 0

while i < 5:

    i += 1

    if i == 3:
        continue

    print(i)
 
Output:-
1
2
4
5
 
Explanation:-

जब i = 3 होता है, तो continue execute होता है और उस iteration का print(i) skip हो जाता है। फिर loop अगली iteration पर चला जाता है।

English

When i = 3, continue is executed. The print(i) statement is skipped for that iteration, and the loop moves to the next iteration.

Use of continue Statement :-

continue statement का उपयोग मुख्य रूप से:

  1. किसी particular value को skip करने के लिए
    To skip a particular value.
  2. कुछ conditions वाली iterations को छोड़ने के लिए
    To skip iterations that meet a specific condition.
  3. Odd या even numbers को filter करने के लिए
    To filter odd or even numbers.
  4. Unwanted data को skip करने के लिए
    To skip unwanted data.

Related Notes