[[Use this in your program to give the user the option of restarting the program at the end, rather than just quitting.]] [label=beginning] [[Put all your code here.]] [say]\n[/say] [label=terminationLine] [say]"Press X to quit, or R to restart..."[/say] [if=read=="X"] [goto=quit] [elseif=read=="R"] [goto=beginning] [/elseif] [else] [goto=error] [/else] [/if] [label=quit] [exit] [label=error] [say]"Invalid input, try again..."[/say] [goto=terminationLine]
Here's one in C#:
//Put this at the beginning of the program:
beginning:
//
//Put your code here
//
//This is the beginning of the termination process.
termination:
//Asks user to either terminate or restart the program.
Console.WriteLine("Press X to terminate, or R to restart the program...");
//Declares a string to represent if the user wants to exit or restart.
string qr = Console.ReadLine();
//If the user chooses to restart...
if (qr.ToUpper() == "R")
{
//...go back to the beginning...
goto beginning;
}
//...otherwise...
else if (qr.ToUpper() == "X")
{
//...quit, but...
Console.Read();
}
//...if the user presses something else...
else
{
//...give an error message...
Console.WriteLine("Invalid input, please try again...");
//...and restart the termination process.
goto termination;
}
And I have written some in other languages that I don't have handy right now.
How else would you do something like this without labels? What's so bad about labels? Everyone always says that you shouldn't use labels. I just don't get it.
Thanks,
TonicX57

New Topic/Question
Reply



MultiQuote




|