Imma java newbie so I try to learn things. I created a boolean method, it's a small craps game. I need this method is called from main method and keep playing while return value is true (game is won) but stop executing if return value is false. I also need how many times player won. So I created something like this:
while(Craps.play())
{
Craps.play();
i++;
}
System.out.println("In total you won " + i + " times");
i
is initialized as private static int i = 0; //Game counter
But output didn't see me correct. First of all, if the game is lost (return value is false) it wo't stop execution. And it doesn't count winning number correct. For example if 3 games are won, it calculates if he won 2 games.
Is there any logic error with this loop?
Thanks
Craps.play();
in the while condition and in the body may be the problem. – A--C Feb 23 at 22:17Craps#play
function inside thewhile-loop
two times: one as a condition, another inside thewhile
block code – Luiggi Mendoza Feb 23 at 22:17while(Craps.play()){i++; //other logic...}
? – Kent Feb 23 at 22:19