[Solved] How to break out of a while loop in C#. Break not working [closed]


When you enter a number different than 2 you actually read another line which you do not process:

if (answer != 2)
{
    Console.WriteLine("Wrong answer. Press enter to get your next sum");
    Console.ReadLine();
}

Your confusion could be because of this line. Change it to:

if (answer != 2)
{
    Console.WriteLine("Wrong answer. Press enter to get your next sum");
}
else{
    Console.WriteLine("Correct answer");
    break;
}

solved How to break out of a while loop in C#. Break not working [closed]