# Infinite loop i dont understand why

Hi all , i dont understand why my scribe do an infinite loop, can u help me ?

level : the two flowers

# Si le paysan est blessé, les fleurs rétréciront.

def summonSoldiers():
if hero.gold >= hero.costOf(“soldier”):
hero.summon(“soldier”)

def findOptimalCoin(coins):
coinIndex=0
Bcoin= None
Bdistance=0
valeurcoin=0
while coinIndex <len(coins):
coin=coins[coinIndex]
Bdistance= hero.distanceTo(coin)
Bprix=coin.value/Bdistance
if Bprix > valeurcoin:
Bcoin = coin
valeurcoin = Bprix
coinIndex += 1
return Bcoin

loop:

``````if hero.gold >hero.costOf("soldier"):
summonSoldiers()

else:

coins = hero.findItems()
coin = findOptimalCoin(coins)
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)

friends = hero.findFriends()
if friends:
j=0
while j <len(friends):

soldat = friends[j]
enemy = soldat.findNearest(hero.findEnemies())
if soldat.type =="peasant":
paysan = soldat

i=0
while i <len(friends):

soldats = friends[i]
if soldats.type != "peasant":
hero.command(soldats, "move",paysan.pos)

i+=1
if enemy:

if  soldat.type =="soldier" and soldat.distanceTo(enemy) < 10:
while enemy.health >0:
hero.command(soldat, "attack", enemy)

j+=1``````

some one ?

You put your post in the wrong category, so people could miss it.