Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C#
C# Reference
C# Keywords
 continue
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
C# Language Reference
continue (C# Reference)

The continue statement passes control to the next iteration of the enclosing iteration 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.

C#
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 following sections in the C# Language Specification:

  • 5.3.3.10 Break, continue, and goto statements

  • 8.9.2 The continue statement

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Don't be fooled!      OxG ... Thomas Lee   |   Edit   |   Show History
Subtle point: The "continue" statement skips to the end of the "enclosing enclosing iteration statement", not the beginning. This is most apparent in a "do...while" loop, where the "continue" causes the "while" condition to be evaluated before going to the beginning of the loop.
So, you cannot skip the "while" evaluation, even if that is what you expect - or hope for, anyways :-)
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker