Jump to content

C# start over the task method (maybe goto)

Go to solution Solved by Mo5,

do it in a loop. while his option isn't correct just loop it.

So here's the code :

choice = Convert.ToInt32 (Console.ReadLine ());// getting the choice number				if (choice > 9 || choice < 1)					Console.WriteLine ("Wrong cell, Game Failed!");				if (board [choice] != 'X' && board [choice] != 'O')// if the space is free fill with X					board [choice] = 'X';				else // Display error if taken				{					Console.WriteLine ("{0}", choice + " is already taken");					Console.WriteLine ("Wait 2 seconds");					Thread.Sleep (2000);				}

So i'm making a tic tac toe console game and at the end, if the user inputs a taken position for his choice it displays an error. So i need to make a way for him to redo his turn until he picks a free slot. i was think of using goto but didn't know to where to go back

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
https://linustechtips.com/topic/457163-c-start-over-the-task-method-maybe-goto/
Share on other sites

Link to post
Share on other sites

do it in a loop. while his option isn't correct just loop it.

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to post
Share on other sites

do it in a loop. while his option isn't correct just loop it.

do{if(is free if){//do stuffbreak;//breaks out of loop}else{//space taken}}while(true)

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×