Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# goto use - what else to use here?

Tags:

syntax

c#

goto

I know using goto is something most people say to avoid, however I have read on various places that sometimes it is useful if you need simple code. Currently I have very simple program that needs to be repeated if user selects so:

static void Main()
{
    Restart:
    ...

    string UserChoice=Console.ReadLine();
    if (UserChoice=="y")
    goto Restart;
}

Is using goto here really so bad? I just cannot see any other way how to repeat the code without doing loops etc. This seems to be very straightforward and clean way. Or am I missing something?

like image 428
Pietro Avatar asked Sep 24 '10 09:09

Pietro


1 Answers

string userchoice;

do {                

    userchoice=Console.ReadLine();

} while (userchoice=="y");
like image 74
explorer Avatar answered Oct 13 '22 12:10

explorer