Simple While loop in C#

Write a while loop that asks the user to enter the number '5' and loops over and over until '5' is entered. 

When 5 is finally entered, print "Got it!". 




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Whilecave
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = 0;
            while (num != 5)
            {
                Console.WriteLine("Enter number 5");
                string value = Console.ReadLine();
                Int32.TryParse(value, out num);
            }
            Console.WriteLine("Got it!!");
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment