# Infinite loop where there wasn't one before (and shouldn't be)

**URL:** <https://discourse.codecombat.com/t/infinite-loop-where-there-wasnt-one-before-and-shouldnt-be/2811>\
**Category:** Uncategorized\
**Created:** [February 22, 2015, 4:14am UTC](https://discourse.codecombat.com/t/infinite-loop-where-there-wasnt-one-before-and-shouldnt-be/2811 "2015-02-22T04:14:56Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Mr\_Berg](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@Mr\_Berg](https://discourse.codecombat.com/u/Mr_Berg)\
**Post date:** [February 24, 2015, 6:09am UTC](https://discourse.codecombat.com/t/infinite-loop-where-there-wasnt-one-before-and-shouldnt-be/2811/6 "2015-02-24T06:09:02Z")

</div>

I am having similar problems since switching to the `move()` boots:

```python
loop:
    bestCoin = None
    maxRating = 0
    coinIndex = 0
    coins = self.findItems()
    
    while coinIndex < len(coins) and coins and self.gold < 150:
        coin = coins[coinIndex]
        if self.distanceTo(coin) < 20:
            rating = coin.value / self.distanceTo(coin)
            if rating > maxRating:
                maxRating = rating
                bestCoin = coin
        coinIndex += 1
    enemy = self.findNearest(self.findEnemies()) 
    if enemy and self.distanceTo(enemy) < 15:
        self.attack(enemy)
    # elif bestCoin and self.isReady("jump"):
    # self.jumpTo(bestCoin.pos)
    elif bestCoin:
        self.move(bestCoin.pos)
    else:
        pass

```

using this for generic loot/attack (e.g. treasure grove) and it works fine for a while, then it starts bogging down and then throws the infinite loop or slow code error.

---

_[View the full topic](https://discourse.codecombat.com/t/infinite-loop-where-there-wasnt-one-before-and-shouldnt-be/2811)._
