the break statement : Break « Language Basics « C# / C Sharp






the break statement

the break statement
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example4_13.cs illustrates the use of
  the break statement
*/

public class Example4_13
{

  public static void Main()
  {

    int total = 0;

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

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

  }

}

           
       








Related examples in the same category

1.Find the smallest factor of a valueFind the smallest factor of a value
2.Using break with nested loopsUsing break with nested loops