
Continue alters control flow. It is used most often in loop bodies in the C# language. The continue keyword allows you to skip the execution of the rest of the iteration. It jumps immediately to the next iteration in the loop. This keyword is most useful in while loops.
This C# article describes the continue keyword. Continue ends the current loop iteration.

To begin, let's look at a program that uses the continue statement in a while-true loop. In a while-true loop, the loop continues infinitely with no termination point. In this example, we use a Sleep method call to make the program easier to watch as it executes.
A random number is acquired on each iteration through the loop, using the Next method on the Random type. Then, the modulo division operator is applied to test for divisibility by 2 and 3. If the number is divisible, then the rest of the iteration is aborted, and the loop restarts.
Program that uses continue keyword [C#]
using System;
using System.Threading;
class Program
{
static void Main()
{
Random random = new Random();
while (true)
{
// Get a random number.
int value = random.Next();
// If number is divisible by two, skip the rest of the iteration.
if ((value % 2) == 0)
{
continue;
}
// If number is divisible by three, skip the rest of the iteration.
if ((value % 3) == 0)
{
continue;
}
Console.WriteLine("Not divisible by 2 or 3: {0}", value);
// Pause.
Thread.Sleep(100);
}
}
}
Output
Not divisible by 2 or 3: 710081881
Not divisible by 2 or 3: 1155441983
Not divisible by 2 or 3: 1558706543
Not divisible by 2 or 3: 1531461115
Not divisible by 2 or 3: 64503937
Not divisible by 2 or 3: 498668099
Not divisible by 2 or 3: 85365569
Not divisible by 2 or 3: 184007165
Not divisible by 2 or 3: 1759735855
Not divisible by 2 or 3: 1927432795
Not divisible by 2 or 3: 648758581
Not divisible by 2 or 3: 1131091151
Not divisible by 2 or 3: 1931772589
Not divisible by 2 or 3: 283344547
Not divisible by 2 or 3: 1727688571
Not divisible by 2 or 3: 64235879
Not divisible by 2 or 3: 818135261...
Branch statements. The C# language is a high-level language. When it is compiled, it is flattened into a sequence of instructions. With the continue statement, branch statements are generated. In branch statements, a condition is tested, and based on whether the condition is true, the runtime jumps to another instruction in the sequence. The continue statement could be implemented by branching to the top of the loop construct if the result of the expression is true.
Sleep Random
The continue statement offers a way to exit a single iteration of a loop, without terminating the enclosing loop entirely and without leaving the enclosing function body. Continue statements can be duplicated by using carefully placed goto statements. Often, continue statements are most useful in while loops, or do-while loops. For-loops may not benefit as much because they usually have well-defined exit conditions.
While Do While For Loop Constructs