Navigating the Dynamics of Continue and Break Statements in C#

Firat Tonak
2 min readJan 21, 2023

--

In this concise article, let’s delve into the intriguing disparities between the Continue and Break statements.

The continue statement takes center stage as it gracefully skips a line, seamlessly transferring the process back to the loop’s inception.

for (int i = 0; i < 10; i++)
{
if (i == 7)
{
continue;
}
Console.WriteLine(i);
}

As you can see above, we skipped the number 7 and transferred the process to the beginning of the loop.

The break statement, on the other hand, serves a different purpose — it allows the process to exit the loop or current situation, in other words, acting as the key to liberating the statement from its loop-bound constraints.

for (int i = 0; i < 10; i++)
{
if (i == 7)
{
break;
}
Console.WriteLine(i);
}

As you can see above, the loop was iterated up to 7 and then exited. You can access the code here.

--

--

Firat Tonak
Firat Tonak

Written by Firat Tonak

Seasoned Senior Full-Stack .NET Developer sharing hands-on experience and cutting-edge technologies in comprehensive Full-Stack development. #TechInsights

No responses yet