• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using input for an 'if' statement.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, that does help
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic