I have a command line asking the user to say (Y/N) and this value is passed to the checkResponse method.
For some reason the while loop ignores the value even though when I debug it’s showing the value is “Y”. It also continues to loop when the value is set to “N”. If I move the if statements below the while statement, the program half way works. I can send up an initial value of “Y” and the while statement will ignore it and start running the code inside of it.
Any idea what I’m missing or over-looking?
Thanks in advance.
public void checkResponse(string response, string confirmValue)
{
Console.WriteLine(response);
Console.WriteLine(response);
if (response == "Y")
{
return;
}
else if (response == "N")
{
Environment.Exit(0);
}
else
{
while ((response != "Y") || (response != "N"))
{
Console.Clear();
Console.WriteLine("\"" + response + "\" is not a valid response.");
Console.WriteLine();
Console.WriteLine("You entered:" + confirmValue);
Console.WriteLine("Is this correct? (Y/N)");
response = Console.ReadLine().ToUpper();
}
}
}
Change from
ORto anANDlogical operator: