# Problem with Preferential Treatment level

**URL:** <https://discourse.codecombat.com/t/problem-with-preferential-treatment-level/11214>\
**Category:** Adventurer\
**Created:** [April 17, 2017, 10:59am UTC](https://discourse.codecombat.com/t/problem-with-preferential-treatment-level/11214 "2017-04-17T10:59:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![muwiras](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/muwiras/32/6211_2.png) [@muwiras](https://discourse.codecombat.com/u/muwiras)\
**Post date:** [April 17, 2017, 10:59am UTC](https://discourse.codecombat.com/t/problem-with-preferential-treatment-level/11214/1 "2017-04-17T10:59:57Z")

</div>

need help. am I doing it right? the second loop seems problem. I don’t know what it is. -\_-’

```python
// First, loop through all enemies...

var enemies = hero.findEnemies();
var enemyIndex = 0;
// ... but only attack "thrower" type enemies.
while (true) {
    
    var enemy = enemies[enemyIndex];
    if(enemy) {
        if(enemy.type === "thrower") {
            hero.attack(enemy);
        }
    }
    enemyIndex +=1;
}

// Then loop through all the enemies again...
enemies = hero.findEnemies();
enemyIndex = 0;
// ... and defeat everyone who's still standing.

  while ( enemyIndex < enemies.length ) {
    enemy = enemies[enemyIndex];
    
    while(enemy.health > 0) {
     hero.attack(enemy);
        
    }
    

    enemyIndex +=1;
    
}

```

---

<div class="post-metadata">

**Author:** ![Hellenar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellenar/32/9100_2.png) [@Hellenar](https://discourse.codecombat.com/u/Hellenar)\
**Post date:** [April 17, 2017, 11:32pm UTC](https://discourse.codecombat.com/t/problem-with-preferential-treatment-level/11214/2 "2017-04-17T23:32:38Z")

</div>

Problem with indentation  
This is what it should be.

```python
enemies = hero.findEnemies();
enemyIndex = 0;
while ( enemyIndex < enemies.length ) {
    enemy = enemies[enemyIndex];
    while (enemy.health > 0) {
        hero.attack(enemy);
    }
    enemyIndex += 1;
}

```

Do same to other bit of code and define enemyIndex and enemies at the top.

---

<div class="post-metadata">

**Author:** ![muwiras](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/muwiras/32/6211_2.png) [@muwiras](https://discourse.codecombat.com/u/muwiras)\
**Post date:** [April 18, 2017, 3:00am UTC](https://discourse.codecombat.com/t/problem-with-preferential-treatment-level/11214/3 "2017-04-18T03:00:14Z")

</div>

thanks a lot. Succeed 😃

a mistake at `while(true)`
