• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using input for an 'if' statement.

 
Nate And
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nate And
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that does help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic