C# – continue Statement
Last Updated :
14 Oct, 2020
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:
Example 1:
C#
using System;
class GFG{
static public void Main ()
{
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#
using System;
class GFG{
static public void Main ()
{
int x = 0;
while (x < 8)
{
x++;
if (x < 2)
continue ;
Console.WriteLine(x);
}
}
}
|
Output:
2
3
4
5
6
7
8
Share your thoughts in the comments
Please Login to comment...