Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Always get line 8:type error: statement execution limit reached

pls help,I couldn’t figure out.
always get line 8:type error: statement execution limit reached
what’s the issue here?

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

// Wrap this into a loop that iterates over all coins.
  while(coinIndex < coins.length) { 
        var coin = coins[coinIndex];
        // Gold coins are worth 3.
        if (coin.value == 3) {
            // Only pick up gold coins.
            hero.moveXY(coins.pos.x, coins.pos.y);
            coinIndex += 1;

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

Can you use use this button: </> and put your code down? It helps everyone help you.

ok i did that defswf

1 Like

What level is this?

its called shine getter on the desert map

Statement execution limit usually means something is stuck in an infinite loop. In this case, it’s your loop going across all coins.

Think carefully about what happens if it’s currently inspecting, say, a silver coin (coin.value == 2). Since the if statement isn’t run, coinIndex is never incremented, and the loop will run again inspecting the same coin. Repeat forever.

To solve this you’ll want to move coinIndex += 1 out of the if statement. Regardless of whether the coin is a gold coin or not, you don’t want to handle it again, so increment to the next one.

1 Like

ok ill try that thanks

it worked thank you :smiley:


Please, select the post which helped you to solve the level.