Continue Statement In C. The continue statement is used in the body of the loop. It is used to move the control to the start of the loop body. When this statement is executed in the loop body, the remaining Statements of the current iteration are not executed. The control directly moves to the next iteration.

Example

  int x;

 for(z = 1; x<=5; x++)

 {

   cout<<” Hello Zitoc \n”;

   continue;

   cout<<” Knowledge is power”;

 }

Explanation

The above example has two cout statements. One statement is before the continue statement and one is after continuing statement. The second statement is never executed This is because each time continues statement is executed, the control moves back to the start of the body. So “Knowledge is power” is never displayed.

Program:

Write a program that displays the sum of the following series. 1+3+5+7+…….100

  #include

  #include

  using namespace std;

  void main()

  {

 int sum = 0;

 for(int i =1; i<100; i++)

 {

    if(i % 2 ==0)

      continue;

   sum = sum +i;

 }

 cout<<”The sum is ”<<sum;

 getch();

   }

Continue and break Statement

Continue and break Statement 'continue' Statement The continue statement is used in the body of the loop. It is used to move the control to the start of the loop…

Continue Reading Continue and break Statement