After searching for a Solution with a do-while Loop, I'm now stuck and this point, and just cant figure out what I am doing wrong.
static void StartUp()
{
bool confirmChoice = false;
Console.WriteLine("Hey, Enter your Character Name!");
string name = Console.ReadLine();
do
{
Console.WriteLine("Is " + name + " correct? (y) or would you like to change it (n)?");
string input = Console.ReadLine();
if (input == "n")
{
Console.WriteLine("Allright, enter your new Name then!");
name = Console.ReadLine();
break;
}
else
{
confirmChoice = true;
}
}while(confirmChoice);
}
Your code is almost right - all you need to do is inverting the condition of your
do
/while
loop towhile (!confirmChoice)
However, you could do better than that: make a forever loop, and use
break
to exit it:This is a common solution for situations when the decision to exit is made in the middle of the loop body.