Do While Loop In C# Console Application

- 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");
        }

    }


Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

1 comments: