title: Changing a for-loop into a recursive function
body: <p>so I've read that you can turn any loop into a recursive function, and I was wondering how I might be able to turn the code below (prints out the permutations of a string) into one (replacing the for loop with a recursive function). I'm not asking for a solution, but rather the way of thinking to approach such a task. Thanks!</p>
  
  <pre><code>private static void permutation(String prefix, String str) {
  
   int n = str.length();
  
    if (n == 0) System.out.println(prefix);
  
    else {
  
      for (int i = 0; i &lt; n; i++)
         permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
    }
  }
  </code></pre>
  
  <p>Thanks everybody!</p>