title: Turning a recursive function into a for loop?
body: <p>Does every recursive function have an equivalent for loop? (Both achieve the same result).</p>
  
  <p>I have this recursive function:</p>
  
  <pre><code>private static boolean recur(String word, int length) {
      if(length == 1 || length == 2)
          return false;
      if(length == 0)
          return true;
      if(words[length].contains(word.substring(0, length)))
          return recur(word.substring(length), word.length() - length);
      return recur(word, length-1);
  }
  </code></pre>
  
  <p>Given that words is a Set[], and where words[i] = a set with words of length i.</p>
  
  <p>What am trying to do is:
  initiate the recursion with a word (say, "stackoverflow", no spaces), I am trying to find if this word can be cut into subwords ("stack", "over", "flow") .. minimum length of a subword is 3, and given that the subword of lenght i is in the Set words[i].</p>
  
  <p>I can confirm this code works, but it may have a memory problem, so I want to turn it to a loop.. if possible.</p>
  
  <p>Do you need more info??</p>
  
  <p>Thanks.</p>