C# continue Statement
The continue statement in C# is somewhat similar to the break statement. However, instead of forcing termination, the continue statement skips the current iteration of the loop and forces the next iteration to occur.
For a for loop, the continue statement causes the condition test and increment part to be executed. For while and do...while loops, the continue statement causes the program control to return to the condition test.
Syntax
The syntax for the continue statement in C#:
continue;
Flowchart
Example
Example
using System;
namespace Loops
{
class Program
{
static void Main(string[] args)
{
/* Local variable definition */
int a = 10;
/* do loop execution */
do
{
if (a == 15)
{
/* Skip the iteration */
a = a + 1;
continue;
}
Console.WriteLine("Value of a: {0}", a);
a++;
} while (a < 20);
Console.ReadLine();
}
}
}
When the above code is compiled and executed, it produces the following result:
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