How to use while to read user input until user decides to exit in C#

1 Answer

0 votes
using System;

public class Program
{
    public static void Main()
    {
        Console.WriteLine("Enter 'q' to quit");
        string input = Console.ReadLine();

        while ((input != "q")) {
            Console.WriteLine("You typed: " + input);
            Console.WriteLine("Enter 'q' to quit");
            input = Console.ReadLine();
        }

        Console.WriteLine("END");
    }
}




/*
run:

Enter 'q' to quit
c#
You typed: c#
Enter 'q' to quit
c
You typed: c
Enter 'q' to quit
c++
You typed: c++
Enter 'q' to quit
q
END

*/

 



answered Aug 3, 2022 by avibootz

Related questions

1 answer 278 views
278 views asked Apr 21, 2017 by avibootz
2 answers 364 views
1 answer 260 views
1 answer 245 views
2 answers 349 views
...