C Sharp Continue Statement

C# Continue Statement

To continue the loop or the current flow of the program and to skip the remaining code at the given condition, the C# continue statement is used. When used inside an inner loop, it continues the inner loop only.

Syntax:

jump-statement;    
continue;   

Example:

using System;  
public class Example  
    {  
      public static void Main(string[] args)  
      {  
          for (char i = 'a'; i <= 'p'; i++)  
          {  
              if (i == 'f')  
              {  
                  continue;  
              }  
              Console.WriteLine(i);  
          }  
      }  
   }

Output:

Explanation:

In the above example, we are displaying the working and behavior of the Continue statement when used inside a loop.

C# Continue Statement with Inner Loop:

When the Continue statement is used inside the inner loop, the C# Continue statement continues the inner loop only.

Example:

using System;  
public class Example  
    {  
      public static void Main(string[] args)  
      {  
          for(char i='a'; i<='d'; i++){      
                    for(int j=1; j<=4; j++){      
                        if(i=='c' && j==2){      
                            continue;      
                        }      
                        Console.WriteLine(i +" "+ j);      
                    }      
          }      
      }  
   }

Output:

Explanation:

In the above example, we are displaying the working and behavior of the Continue statement when used inside an inner loop.

Please Share