Two Laptop Bag
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using input for an Watch "Using input for an New topic

Using input for an 'if' statement.

Nate And

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

Joined: Jan 10, 2002
Posts: 63858

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).

[Asking smart questions] [About Bear] [Books by Bear]
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

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

Joined: Aug 17, 2003
Posts: 2
Thanks, that does help
I agree. Here's the link:
subject: Using input for an 'if' statement.
It's not a secret anymore!