[JavaScript] What causes "Infinite Loop" Error?

Everybody knows that Infinite Loops errors are the most annoying. What I can’t seem to figure out is what causes them. My guesses are network latency, too much loop nesting, etc. But even if I fix this stuff, it still seems to give me the error. Sometimes it gives me the error when there’s a while-loop in a while-loop. Sometimes it gives it in bizzare situations.
Also, if somebody can tell me what’s causing the infinite loop error in the code below, can you tell me?

while(true) { var coins = hero.findItems(); var coinIndex = 0;
while (coinIndex < coins.length) {

var coin = coins[coinIndex];
// Gold coins are worth 3.
if (coin.value == 3) {
    hero.moveXY(coin.pos.x, coin.pos.y);
    coinIndex += 1;
(Oh, by the way, the level is Shine Getter.)

You increase coinIndex only if a coin’s value is 3, otherwise coinIndex doesn’t change.