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 Using input for an 'if' statement. 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 "Using input for an Watch "Using input for an New topic
Author

Using input for an 'if' statement.

Nate And
Greenhorn

Joined: Aug 17, 2003
Posts: 2
Okay. I can create and access user input and then manipulate it. What I want to do is create an 'if else' statement that depends if the user entered 'yes' or 'no' and then go on in the program accordingly. I want 'yes' to go somewhere else in the program and to display a 5 second message before doing so and 'no' to exit the program. How do I go about doing this? I know I need some sort of a label in the program but every time I try it I get a compilation error.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

It'd be easier to help you with your problem if you'd actually post the error message you are getting. In fact, show us your code too (and be sure to use the UBB code tags so that the formatting of your code will be preserved).
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Hi, Nate, and welcome to JavaRanch!
A label is not really the route that you want to go; most modern programming paragidms discourage the use of labels. Object-oriented programming does this in particular; it is too "proceedure-oriented."
That being said, there has to be some amount of procdures in any code; if-else statements and the like are testament to that. What you really want to do is create separate methods (sort of like using labels, but more like sub-routines) for your code.
What follows is a sample of the type of structure that you would use to acheive what you describe

Hope this helps. If you have any further questions, we are here to help.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Nate And
Greenhorn

Joined: Aug 17, 2003
Posts: 2
Thanks, that does help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using input for an 'if' statement.
 
Similar Threads
Timer Function
catch statements
Loop help
Using input for an 'if' statement.
Trouble with Guessing Game