Infinite loop in cavern survival

here is my code

while(true) {
    var enemy = hero.findNearestEnemy();
    
    var friends=hero.findFriends();
    var i=0;
    if (hero.gold>20) {
        this.summon("soldier");
    }
    
    while (i<friends.length) {
        var friend=friends[i];
        if (friend) {
            hero.command(friend, "defend", hero);
        }
    }
    if (hero.isReady("warcry")) {
        hero.warcry();
    }
    else if (hero.isReady("throw")) {
        hero.throw(enemy);
    }
    else {
        hero.shield();
        
    }
}

You haven’t put any code in to increase i, so the second while loop will go on for ever…

J.

an easier way to do it would be through using a for loop.

1 for loop does not work 2 @jka2706 thanks for the info

it doesn’t? strange. it should work.