+ 4
Infinite loop problems!
I just finished my first script but it has some infinite loop problems. The code is public. Can someone help me because i dont know how to fix this.
4 Antworten
+ 8
indeed! But mistakes help people learn 😁
+ 7
see your while statement.. It will always return true as one always is alive.
try something like
var playGame = true;
while(playGame) {
if(playerHealth == 0 || dragonHealth == 0)
{
playGame = false;
}
+ 3
https://code.sololearn.com/WR3QSO7sgq25/?ref=app
You're make probably mistake in your loop conditions statements:
while (dragonHealth > 0 || playerHealth > 0)
... will be true until oce variable still is positive, but I guess you want stop the 'while' loop as soon as one of each becomes zero or negative:
while (dragonHealth > 0 && playerHealth > 0)
+ 3
@jay, using 'or' operator better safe by doing:
if (playerHealth <= 0 || dragonHealth <= 0)
;)