File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the best way to get my program to repeat itself?

 
J. Chris Miller
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my program, how do I get it to repeat after it is finished printing?:



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: loop
 
J. Chris Miller
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Hint: loop


I assumed you could use a while loop, but I'm unsure on the format, and I've tried several things. So, I'm still stuck.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show, don't tell. Post your attempt.
 
J. Chris Miller
Ranch Hand
Posts: 30
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I fooled around with the while loop and got it to work finally. Thanks!
 
J. Chris Miller
Ranch Hand
Posts: 30
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the updated code:

 
Sumit Bisht
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris!
The only problem that I see in your code is that your loop has got no exit condition. It might be helpful to have a confirmation by the user at the end to continue with the execution or not and set the variable game correctly or have a special case such as anything other than 1-99 which will break from the loop.
As of now, only a ParseException will end the loop, which is not the best approach always.
 
Winston Gutkowski
Bartender
Pie
Posts: 9477
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Chris Miller wrote:Here's the updated code:...

Chris,

Please DontWriteLongLines. It makes your thread very hard to read. I've broken yours up this time, but for future reference, please remember:
80 characters max.
And that includes string literals and comments.

Thanks.

Winston
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic