• Post Reply Bookmark Topic Watch Topic
  • New Topic

Structure question, loop or call program to execute again?  RSS feed

 
Kaiyo Sakamoto
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Morning/Afternoon,

I'm currently working on a small program that asks the user for six words to make a small story or poem filling in with the user input. The program needs to have a yes/no JOption prompt at the end that asks the user to play again with new words or No will exit the program.

Should I use a loop or can I use the prompt to call the program to execute again?

Below is the code please keep in mind this is not done and my poem/story will be edited, Thanks

 
Norm Radder
Rancher
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd vote for a loop instead of a recursive call.
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use Code tags they must have all the code between the begin tag and the end tag. Fixed it for you this time.
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Norm Radder suggests, a loop would be much clearer.
However, I would not put all of that code in the main() method. You could do something like this:

Even better would be to put everything in an instance of MadLib, and reduce main() to

 
Dave Tolls
Ranch Foreman
Posts: 3061
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd shorten that loop to:

Where 'continuePlaying' does the prompt bit of the code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!