Continue-Statement-In-C .

In this session i have discussed continue statement in C .


The continue is a keyword in c 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 break statement in loop .

    #includ<stdio.h> 
    int main()
    {          
            for(int i=1;i<10;i++)
            {
                if(i==6)
                {
                    continue;
                }
                printf("%d",i);
                printf(" ");
            }
            
            return 0;
    }
    
    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 .

    #includ<stdio.h> 
    int main()
    {          
         int i=1,j=1;    
         for(i=1;i<=3;i++)
         {      
             for(j=1;j<=3;j++)
             {    
                if(i==2 && j==2)
                {    
                   continue;    
                }    
                printf("%d %d\n",i,j);    
             }    
         }
        return 0;
    }
    
    OUTPUT : 1 1
             1 2
             1 3
             2 1
             3 1 
             3 2
             3 3
    

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

    #includ<stdio.h> 
    int main()
    {          
            int i=1;
            while(i<=10)
            {
                if(i==6)
                {
                    i++;
                    continue;
                }
                printf("%d",i);
                printf(" ");
                i++;
            }
            return 0;
    }
    
    OUTPUT : 1 2 3 4 5 7 8 9 10
    

Welcome to AndroidATPoint.

back image                     next image