C# continue Statement

C# loops

In C#continueThe statement is somewhat likebreakstatement. But it is not a forced termination; continue skips the code in the current loop and forces the next iteration to begin.

forforloop,continuestatement causes the condition test and loop increment portion to be executed. Forwhileanddo...whileloop,continuestatement causes program control to return to the condition test.

Syntax

In C#continue Syntax of the statement:

continue;

Flowchart

C# 中的 continue 语句

Example

Example

using System;

namespace Loops
{
   
    class Program
    {
        static void Main(string[] args)
        {
            /* local variable definition */
            int a = 10;

            /* do loop execution */
            do
            {
                if (a == 15)
                {
                    /* Skip iteration */
                    a = a + 1;
                    continue;
                }
                Console.WriteLine("Value of a: {0}", a);
                a++;

            } while (a < 20);
 
            Console.ReadLine();
        }
    }
}

When the above code is compiled and executed, it produces the following results:

a 的值: 10
a 的值: 11
a 的值: 12
a 的值: 13
a 的值: 14
a 的值: 16
a 的值: 17
a 的值: 18
a 的值: 19

C# loops

other extensions