Continue-Statement-In-Python .

In this session i have discussed continue statement in Python .


The continue is a keyword in Python which is used in loop . When a continue statement is encountered inside a loop, control jumps to the beginning of the loop for next iteration, skipping the execution of statements inside the body of loop for the current iteration .

Example : Write a program that will demonstrate the continue statement in for loop .


for i in range(1,11):
    if(i==6):
                
        continue
                
    print(i,end=" ")
    
    OUTPUT : 1 2 3 4 5 7 8 9 10
    

6 is missing in above program because of continue statement


Example : Write a program that will demonstrate the continue statement in nested loop .

i=1
j=1    
for i in range(1,4):
               
    for j in range(1,4):
        if(i==2 and j==2):
                    
            continue    
                    
        print(i,j);    
    print("\n")           
         
    
    OUTPUT : 1 1
             1 2
             1 3
             2 1
             2 3
             3 1 
             3 2
             3 3
    

Example : Write a program that will demonstrate the continue statement in while loop .

i=1
while i<=10:
    if i==6:
        i=i+1
        continue
                
    print(i,end=" ")
    i=i+1
     
    
    OUTPUT : 1 2 3 4 5 7 8 9 10
    

Welcome to AndroidATPoint.

back image                     next image