The moose likes Beginning Java and the fly likes while loop not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "while loop not working?" Watch "while loop not working?" New topic

while loop not working?

mary caldwell

Joined: Oct 16, 2008
Posts: 9
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 ]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46405
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".
Dragan Stankovic
Ranch Hand

Joined: Oct 14, 2008
Posts: 33
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.
I agree. Here's the link:
subject: while loop not working?
It's not a secret anymore!