Continue Statement

C#C# continue statement is used to skip some piece of code inside the loop.  In some cases, you don’t want to execute some piece of code during your looping process, then this statement comes in handy.  The C# sample code is given below to demonstrate the use of continue statement where we are skipping 1 name from printing on the screen.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
namespace MyHelloWorld
{
class Program
{
static void Main(string[] args)
{
string[] names = { "Robert", "Albert", "Mark" };
foreach (string name in names)
{
if (name == "Albert")
{
continue;
}
Console.WriteLine(name);
}
}
}
}
using System; namespace MyHelloWorld { class Program { static void Main(string[] args) { string[] names = { "Robert", "Albert", "Mark" }; foreach (string name in names) { if (name == "Albert") { continue; } Console.WriteLine(name); } } } }
using System;

namespace MyHelloWorld
{   
    class Program
    {
        static void Main(string[] args)
        {
            string[] names = { "Robert", "Albert", "Mark" };

            foreach (string name in names)
            {                

                if (name == "Albert")
                {
                    continue;
                }

                Console.WriteLine(name);
            }

        }
    }
}

 

Output:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Robert
Mark
Press any key to continue . . .
Robert Mark Press any key to continue . . .
Robert
Mark
Press any key to continue . . .