Help Sarven Shepherd error "hard execution limit of 3000000 exceeded"


#1
# Use while loops to pick out the ogre
while True:
    enemies = hero.findEnemies()
    enemyIndex = 0
# Wrap this logic in a while loop to attack all enemies.
# Find the array's length with:  len(enemies)

    while enemyIndex < len(enemies):
           enemy = enemies[enemyIndex]
         # "!=" means "not equal to."
           if enemy.type != "sand-yak":
            # While the enemy's health is greater than 0, attack it!
              while enemy.health > 0:
                  hero.attack(enemy)
              enemyIndex += 1
        pass
    # Between waves, move back to the center.
        hero.moveXY(40, 32)

Every time I run my code I get the error “Hard execution limit of 3000000 exceeded” and my hero just stands there doing nothing.

What is wrong with my code?


#2
enemyIndex += 1

remove one tab before that (4 spaces)

it’s indented 1 times too many and it’s part of the ‘if’ statement now, therefore once the if statement returns false (which happens when it selects the yak and then does nothing) it will never increment your iterator and your while loop will keep running forever.


#3

Thank you for the help.