Saturday, December 9, 2017

Continue Statement In C

We know loop continues execution of its body statements until the condition is false. If I want to skip some statements inside loop or terminate execution before the loop condition becomes false. How can we handle this issue ?

To solve this issue there are some case control statements in C programming.

  • break
  • continue
  • switch

Continue Statement

  • Continue statement is used in C programming to skip remaining code after the continue statement inside the body of any loop.
  • To write continue statement in our program we use decision making statement ( if - else ).

Syntax of Continue Statement : continue;

Example

#include <stdio.h>

int main()
{
    int i;
    for(i = 1; i <= 10; i++)
    {
        if(i == 3 || i == 5 || i == 7)
        {
            continue;
        }

        printf("%d \n", i);
    }
    return 0;
}



Output
1
2
4
6
8
9
10

Explanation of above program

If you notice the output section then you will see 3, 5 and 7 is missing though we set the loop for all number between 1 to 10 inclusive. We set another condition in the body of the for loop which means that if the number is 3, 5 or 7 only then it will skip the remaining body statents and it will start the next iteration.



Previous Topic

Next Topic



No comments:

Post a Comment