The Wayback Machine - https://web.archive.org/web/20240204105051/https://www.geeksforgeeks.org/c-sharp-continue-statement/
Open In App
Related Articles

C# – continue Statement

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

In C#, the continue statement is used to skip over the execution part of the loop(do, while, for, or foreach) on a certain condition, after that, it transfers the control to the beginning of the loop. Basically, it skips its given statements and continues with the next iteration of the loop. Or in other words, the continue statement is used to transfer control to the next iteration of the enclosing statement(while, do, for, or foreach) in which it appears.

Syntax: 

continue;

Flow Chart:

C# - continue Statement

Example 1:

C#




// C# program to illustrate the use
// of continue statement in for loop
using System;
  
class GFG{
    
static public void Main ()
{
      
    // Here, in this for loop start from 2 to 12, 
    // due to the continue statement, when x = 8
    // it skip the further execution of the statements
    // and transfer the controls back to the 
    // next iteration of the for loop
    for(int x = 2; x <= 12; x++)
    {
        if (x == 8)
        {
            continue;
        }
        Console.WriteLine(x);
    }
}
}


Output:

2
3
4
5
6
7
9
10
11
12

Example 2: 

C#




// C# program to illustrate the use
// of continue statement in while loop
using System;
  
class GFG{
    
static public void Main ()
{
    int x = 0;
      
    // Here, using continue statement
    // whenever the value of x<2, it
    // skips the further execution of the
    // statements and the control transfer
    // to the next iteration of while loop
    while (x < 8)
    {
        x++;
  
        if (x < 2)
            continue;
  
        Console.WriteLine(x);
    }
}
}


Output:

2
3
4
5
6
7
8

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!


Last Updated : 14 Oct, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads