Wednesday

Continue statement


Continue statement

                  continue statement is a jump statement. The continue statement can be used only inside for loop, while loop and do-while loop. Execution of these statement does not cause an exit from the loop but it suspend the execution of the loop for that iteration and transfer control back to the loop for the next iteration.

The following program illustrates the use of  continue statement.



/*demonstration of continue statement*/
      #include<stdio.h>
      #include<conio.h>
         int main()
     {
            int i,j;
            for(i=1; i<=2; i++)
         {
            for(j=1; j<=2; j++)
          {
            if(i==j)      //if i==j this statememt is true that continue will execute and skip it//
            continue;
            printf("\n%d %d",i,j);
          }
        }
       getch();
      return 0;
   }
    Output:
      1 2
      2 1

Explanation: When the value of i equals that of j, the continue statement takes the control to the for loop(inner) bypassing the rest of the statements execution in the for loop(inner).

Let's understand continue statement with another example:

/*demonstration of continue statement*/
  #include<stdio.h>
  #include<conio.h>
  int main()
  {
    int i;
    for(i=1; i<=10; i++)
   {
      if(i==6)
     continue;
    printf("%d ",i);
    }
   printf("\nNow we are out of for loop");
   getch();
   return 0;
}

 Output:-

 1 2 3 4 5 7 8 9 10
 Now we are out of for loop

Explanation: As when the value of i will becomes 6 it will move for the next iteration by skipping the iteration i=6.

Kindly Bookmark this Post using your favorite Bookmarking service:
Technorati Digg This Stumble Stumble Facebook Twitter
YOUR ADSENSE CODE GOES HERE

0 comments:

Post a Comment

Dont Forget for Commets

 

| C programing tutorials © 2009. All Rights Reserved | Template Style by My Blogger Tricks .com | Design by Brian Gardner | Back To Top |