Use if statement to control continue statement in CSharp

Description

The following code shows how to use if statement to control continue statement.

Example


public class MainClass {     
/*w  w  w .j  a  va 2  s.  c  om*/
  public static void Main()
  {

    int total = 0;

    for (int counter = 1; counter <= 10; counter++)
    {
      if (counter == 6)
      {
        System.Console.WriteLine("continue from loop start");
        continue;
      }
      System.Console.WriteLine("counter = " + counter);
      total += counter;
    }

    System.Console.WriteLine("total = " + total);

  }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    C# Language »




C# Hello World
C# Operators
C# Statements
C# Exception