continue (C# Reference)

 

Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

The continue statement passes control to the next iteration of the enclosing while, do, for, or foreach statement in which it appears.

In this example, a counter is initialized to count from 1 to 10. By using the continue statement in conjunction with the expression (i < 9), the statements between continue and the end of the for body are skipped.


    class ContinueTest
    {
        static void Main()
        {
            for (int i = 1; i <= 10; i++)
            {
                if (i < 9)
                {
                    continue;
                }
                Console.WriteLine(i);
            }

            // Keep the console open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
    /*
    Output:
    9
    10
    */

For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.

C# Reference
C# Programming Guide
C# Keywords
break Statement
Jump Statements

Show: