By 22/07/2015 37 Comments

C# Continue Statement

  • C# continue statement works same as break statement.
  • It can be used in for, foreach, while and do while loop.
  • continue statement skips or exits the current execution of a loop by given condition and keep execution continue for its next iteration unlike break statement it does not exit or terminate from loops, it terminates only its current execution.

Example – 1, using continue┬ástatement with for loop:

using System;
namespace csharpBasic
{
    // Start class definition / declaration.
    class Program
    {
        // Static main method void type declaration.
        static void Main(string[] args)
        {
            // for loop initializing.
            for (int countNumber = 1; countNumber <= 10; countNumber++)
            { // for loop is started.
                
                // if condition.
                if (countNumber == 6)
                    continue; // continue statement.

                // Print countNumber variable.
                Console.WriteLine("Number: {0}", countNumber);

            } // End of for loop.

            Console.ReadKey();

        } // End of main method definition. 
    } // End of class. 

    /*
    The Output will be:
    Number: 1
    Number: 2
    Number: 3
    Number: 4
    Number: 5
    Number: 7
    Number: 8
    Number: 9
    Number: 10
  */
}


Example – 2, using continue statement with foreach loop.

using System;
namespace csharpBasic
{
    // Start class definition / declaration.
    class Program
    {
        // Static main method void type declaration.
        static void Main(string[] args)
        {
            // String type array initialization.
            string[] pLanguages = { "C#", "Php", "Asp.NET", "Jquery" , "Css" , "Html" , "Xml" };

            // foreach loop declaration.
            foreach (string show in pLanguages)
            { // foreach loop is started.

                // if condition checking.
                if (show == "Php" || show == "Jquery")
                    continue; // continue statement.

                // Print show variable.
                Console.WriteLine(show);

            } // End of foreach loop.

            Console.ReadKey();

        } // End of main method definition. 
    } // End of class. 

    /*
    The Output will be:
    C#
    Asp.NET
    Css
    Html
    Xml
    
  */
}





Next Tutorial →


← Previous Tutorial


Posted in: C# Basics, C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .