Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

while loop not working?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again,
I'm coding a game that has to allow the user to play a certain number of turns before losing. For some reason the game plays perfectly through the first turn, and then skips directly to game over. The weird thing is that I've tried debugging this by sticking in a println call at the end of each turn, and those are working... so it IS running through each turn, but not letting the user play for the 2nd and 3rd turns. If anyone can help by taking a look at the code below, that would be awesome. Thanks a million in advance!

[edit]Add newlines to shorten long lines. CR[/edit]
[ October 21, 2008: Message edited by: Campbell Ritchie ]
 
Marshal
Posts: 76113
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many of us think that while(true) { . . . break; . . . } is bad design. Have a look at our style guide for an explanation.

I haven't been able to go through your loop, but it is most likely you are calling "break;" regardless.
You can eliminate the break very simply by choosing what goes after "while".
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please add values for your constants so I can see some meaningful graphics. I tried to put values on my own but I got some weird graphics so I couldn't understand what was your game about and what is not working properly.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic