• Post Reply Bookmark Topic Watch Topic
  • New Topic

while loops for class  RSS feed

 
Troy Turley
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm a beginner programmer. I'm checking conditions using while loops. They are good until the second while at the end where I ask the user one final time ("Do you wish to buy or sell?"). Technically, it works correctly too rechecking for a matching condition. However, I'd the code to start again from the very top before the first while loop at the first ("Do you wish to buy or sell?").

This is my fist post. Hopefully, someone can chip in a few ideas to help me.

 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Please UseCodeTags (<- that's a link) when posting code. I'll do it for you this time.
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I'd use do / while loops so that you don't repeat code. And only loop until you get valid input. What you do with that input can be done outside the loop.

The put a big loop around the whole thing. Ask, "Do you want to buy, sell, or quit?" Break out of the big loop if the user answers "quit".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!