- Run Visual Studio
- Crate new project in Console Application
- Write those Code .
- Then RUN ..
Do While Loop Syntax :
do {
statement(s);
} while( condition );
FLOW CHART :
EXAMPLE CODE :
class Program
{
static void Main(string[] args)
{
string UserChoise = string.Empty;
do
{
Console.WriteLine("Please enter your tatget ?");
int UserTarget = int.Parse(Console.ReadLine());
int Start = 0;
while (Start <= UserTarget)
{
Console.WriteLine(Start);
Start = Start + 2;
}
do
{
Console.WriteLine("Do you want to continue - YES or NO ?");
UserChoise = Console.ReadLine().ToUpper();
if (UserChoise != "YES" && UserChoise != "NO")
{
Console.WriteLine("Invalid Choise, Please say YES or NO ");
}
} while (UserChoise != "YES" && UserChoise != "NO");
} while (UserChoise == "YES");
}
}
- Crate new project in Console Application
- Write those Code .
- Then RUN ..
Do While Loop Syntax :
do {
statement(s);
} while( condition );
FLOW CHART :
EXAMPLE CODE :
class Program
{
static void Main(string[] args)
{
string UserChoise = string.Empty;
do
{
Console.WriteLine("Please enter your tatget ?");
int UserTarget = int.Parse(Console.ReadLine());
int Start = 0;
while (Start <= UserTarget)
{
Console.WriteLine(Start);
Start = Start + 2;
}
do
{
Console.WriteLine("Do you want to continue - YES or NO ?");
UserChoise = Console.ReadLine().ToUpper();
if (UserChoise != "YES" && UserChoise != "NO")
{
Console.WriteLine("Invalid Choise, Please say YES or NO ");
}
} while (UserChoise != "YES" && UserChoise != "NO");
} while (UserChoise == "YES");
}
}
A detailed tutorial ....C# while loop
ReplyDelete