Cyra
Cyra

Reputation: 1

C#.NET While loop not exiting

This is a short function to check and make user write uppercase Y or N .I dont know why but even if the user enter upper case Y or N , still then the loop does not exit. Any help please?

 static char GetUpperCaseYN()
    {
        char choice='y';
        Console.WriteLine("Calculate Another? Y/N ");
        choice = char.Parse(Console.ReadLine());
        while (choice != 'Y' || choice != 'N')
        {
            Console.WriteLine("Invalid Response.Please enter Y or N");
            choice = char.Parse(Console.ReadLine());
        }
        return choice;
    }

Upvotes: 0

Views: 62

Answers (1)

James
James

Reputation: 499

Use && not ||; they can't both be false with one character :)

Upvotes: 4

Related Questions