This simple program demonstrate the use of while loop in C#. While loop run until condition reaches to false.
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