c# - How do I loop back to the start of an 'if' branch? -
i want loop beginning of 'if' condition if 'else' condition met. i'm new c# programming , struggling quite bit if i'm honest. sorry if has been asked before, did search found nothing.
here's (messy) code:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks;  namespace tinkering {     class program     {         static void main(string[] args)         {              {                 console.writeline("let's go on adventure shall we?\n\nlet's start name:");                 string username = console.readline();                  console.writeline("\nhi " + username);                 console.writeline("\nis girls' name?\n");                 console.readline();                  console.writeline("\ni see\n");                 console.writeline("well anyway, let's started shall we?\n");                 console.writeline("would care go left or right " + username);                  while (userinput)                 {                      string userinput = console.readline();                     if (userinput == "left")                     {                         console.writeline("left is!\nyou see long dark corridor. there sudden empty feeling in stomach, kind of weird feeling feels empty know shit...");                         console.readline();                     }                      else if (userinput == "right")                     {                         console.writeline("ok let's head right\n");                         console.writeline("\nit looks though have locked door here...");                         console.writeline("unfortunately" + username);                         console.writeline("that end of shitty little game (i couldn't bothered writing anymore code lol");                         console.readline();                     }                      else                     {                         console.writeline("just type 'left' or 'right' please");                         console.readline();                     }                 }      
you using console.readline() @ begginning of while loop. delete them end of if block,else if block , else block. code should automatically go if statement
 while (userinput)             {                 string userinput = console.readline();                 if (userinput == "left")                 {                     console.writeline("left is!\nyou see long dark corridor. there sudden empty feeling in stomach, kind of weird feeling feels empty know shit...");                 }                  else if (userinput == "right")                 {                     console.writeline("ok let's head right\n");                     console.writeline("\nit looks though have locked door here...");                     console.writeline("unfortunately" + username);                     console.writeline("that end of shitty little game (i couldn't bothered writing anymore code lol");                 }                  else                 {                     console.writeline("just type 'left' or 'right' please");                 }      
Comments
Post a Comment