Sponsored Ad

Friday, September 24, 2010

While Loop Program Using C# | While Loop Example

This simple program demonstrate the use of while loop in C#. While loop run until condition reaches to false.

image

Code for While Loop:

using System;
using System.Text;
using System.Data;
namespace Console_App
{
    public class clsWhileLoop
    {
        public static void Main()
        {
            try
            {
                Console.WriteLine("Enter a number:");
                int GivenNumber = Convert.ToInt16(Console.ReadLine());
                while (GivenNumber < 10)
                {
                    Console.WriteLine("Loop Count {0} ", GivenNumber);
                    GivenNumber++;
                }
            }
            catch (Exception ex)
            {
                //handle exception here
            }
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates