title: How to avoid StackOverflowError for a recursive function
body: <p>I'm writing a function that will call itself up to about 5000 times. Ofcourse, I get a <code>StackOverflowError</code>. Is there any way that I can rewrite this code in a fairly simple way?:</p>
  
  <pre><code>void checkBlocks(Block b, int amm) {
  
      //Stuff that might issue a return call
  
      Block blockDown = (Block) b.getRelative(BlockFace.DOWN);
      if (condition) 
          checkBlocks(blockDown, amm);
  
  
      Block blockUp = (Block) b.getRelative(BlockFace.UP);
      if (condition) 
          checkBlocks(blockUp, amm);
  
      //Same code 4 more times for each side
  
  }
  </code></pre>
  
  <p>By the way, what is the limitation of how deep we may call the functions?</p>