Saturday, February 4, 2012

How to Use Break statement in C#

Ques: How to break loop before reaching to the end?
Sol: This is a very simple In C# we can achieve this by using the break statement.

                                                          "Simple Example"
using system.
namespace codeImagine
{
class TestClass
{
        public static void Main(string[] args)
      {
         for (int i = 0; i < 10; i++)
         {     
              Console.WriteLine("Number #:" + i.ToString());
              if (i == 4)
                 break;
         }
        Console.WriteLine("Out of loop.");
        Console.ReadLine();
     }
}

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Code Imagine