This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes A command similar to Goto in Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A command similar to Goto in Java?" Watch "A command similar to Goto in Java?" New topic
Author

A command similar to Goto in Java?

Dan Bolens
Greenhorn

Joined: Sep 10, 2012
Posts: 25
Right now my program is supposed to allow users of repeat the program over again or allow them to restart if they make an error. My code is as follows:



If the user enters "N", the program terminates, but how can I make the program start over again if the user says "Y"? I've been looking for something similar to a GOTO statement (which I know you should NEVER use), and I've found the throw and switch commands. I'm a bit confused to how both of these commands work, and how I could fit them into my program. Any help would be much appreciated!
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3013
    
  35

Use a loop. Something like this would do the trick.


Founder of ExamLab and Systemup
See how I can help you to become an awesome programmer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A command similar to Goto in Java?
 
Similar Threads
Help with number guessing game
Bad operand types for binary operator?
unable to log with log4j in tomcat 6.0.29
Trouble with Guessing Game
method help