Conditional loop breaks?


#1

hey guys, this might seem a touch obvious but would really apreciate the help. ive managed to scroll through and kill all the archers on the level im on. the problem is i then want to break the loop and start again but with a different enemy type. my question is how i break the loop once there no archers left? here my code so far:

loop:
enemies = self.findEnemies()
enemyIndex = 0

while enemyIndex < len(enemies):    
    enemy = enemies[enemyIndex]
    if enemy.type == 'archer':
        while enemy.health > 0:
            if self.isReady("cleave"):
                self.cleave(enemy)
            else:
            self.attack(enemy)
    enemyIndex += 1

idealy i want to say something like :

if no enemy.type == ‘archer’:
break

but i cant get my head around it. please help x


#3

Try this:

archer = self.findNearest(self.findByType("archer"))
if not archer:
    break