While loop condition runs infinite

Hi.

Why does this code go to an infinite loop, it is suppose to stop when game time reaches 4?

hero = game.spawnPlayerXY(54, 30)

ui.track(game, "time")

index = 0

while game.time < 4:
    index += 1
    hero.say(index)

    

Thanks

codecombat bug.
do

while True:
    if game.time >= 4:
        break
    stuff()

instead

1 Like

I would suggest putting this into the level help section instead of in the uncategorized place

2 Likes

First off, put this in level help instead.
Second, Python seems to have an occasional issue where the while loop does not break when the loop’s condition was met. This is also a bug in CodeCombat itself. I’ve experienced it a few times. Therefore, add an if statement in the while loop that checks the game.time value and if it’s equal to or greater than 4, exit the loop.

Done! (20 chars are bad)

Thank you! 20 charsss

1 Like

Thanks for all the replies, just needed to confirm if it is a bug or not.

No problem! its our communitys job to help you fix your code