Hey guys,

I’m getting really stuck with these loops. My character just keeps walking straight in to a mine. I have changed the indentation a few times of the MoveXY but it just doesnt work.

Here is my code. Many thanks.

```
while True:
coins = hero.findItems()
coinIndex = 0
nearest = None
nearestDistance = 9999
# Loop through all the coins to find the nearest one.
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
distance = hero.distanceTo(coin)
# If this coin's distance is less than the nearestDistance
if distance < nearestDistance:
# Set nearest to coin
nearest = coin
# Set nearestDistance to distance
nearestDistace = distance
# If there's a nearest coin, move to its position. You'll need moveXY so you don't cut corners and hit a trap.
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
```