How to exit a loop with user input in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Press 'e' to exit");

                var ch = Console.ReadKey().KeyChar;
                Console.WriteLine();
                if (char.ToLower(ch) == 'e') break;
            }
        }
    }
}

/*
run:
   
Press 'e' to exit
d
Press 'e' to exit
t
Press 'e' to exit
e
      
*/

 



answered Apr 21, 2017 by avibootz

Related questions

1 answer 134 views
2 answers 234 views
1 answer 102 views
102 views asked Aug 8, 2024 by avibootz
2 answers 237 views
1 answer 263 views
263 views asked Oct 6, 2015 by avibootz
...