c# - get user confirmation inside a loop -


after searching solution do-while loop, i'm stuck , point, , cant figure out doing wrong.

static void startup() {      bool confirmchoice = false;      console.writeline("hey, enter character name!");     string name = console.readline();         {     console.writeline("is " + name + " correct? (y) or change (n)?");     string input = console.readline();     if (input == "n")     {         console.writeline("allright, enter new name then!");         name = console.readline();         break;     }     else     {         confirmchoice = true;     }     }while(confirmchoice); } 

your code right - need inverting condition of do/while loop while (!confirmchoice)

however, better that: make forever loop, , use break exit it:

while (true) {     console.writeline("please, enter character name!");     string name = console.readline();     console.writeline("is " + name + " correct? (y) or change (n)?");     string input = console.readline();     if (input == "y") {         break;     } } 

this common solution situations when decision exit made in middle of loop body.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -