C++Tutorials

C++ continue control statement

In this article, we will learn about c++ continue control statement, want’s to know about the control statement click here.

Before moving forward I want to recap that control stament has two types-:

  1. Conditional Statement
  2. Unconditional Statement

If you want to know what is a conditional statement, click here .

The C++ continue statement is used to continue loop. It continues the current flow of the program and skips the remaining code at specified condition. In case of inner loop, it continues only the inner loop.

Continue Control Statement Syntax :

jump-statement;      
continue;     

Example : 1

#include <iostream>  
using namespace std;  
int main()  
{  
     for(int i=1;i<=10;i++){      
            if(i==5){      
                continue;      
            }      
            cout<<i<<"\n";      
        }        
}  

Output:

1
2
3
4
6
7
8
9
10

Example:2

C++ Continue Statement continues inner loop only if you use continue statement inside the inner loop.

#include <iostream>  
using namespace std;  
int main()  
{  
 for(int i=1;i<=3;i++){        
            for(int j=1;j<=3;j++){        
             if(i==2&&j==2){        
                continue;        
                        }        
                cout<<i<<" "<<j<<"\n";                  
                    }        
            }            
}  

Output:

1 1
1 2
1 3
2 1
2 3
3 1
3 2
3 3

Example: 3

#include <iostream>
using namespace std;
 
int main () {
   // Local variable declaration:
   int a = 10;

   // do loop execution
   do {
      if( a == 15) {
         // skip the iteration.
         a = a + 1;
         continue;
      }
      cout << "value of a: " << a << endl;
      a = a + 1;
   } 
   while( a < 20 );
 
   return 0;
}

Output:

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button