title: For loop with substrings
body: <p>Beginning CS student here, trying to get a handle on loops. My task is to take a String s, such that if <code>s = 'abcd'</code>, the program will print: <code>'a,b,c,d,ab,bc,cd,abc,bcd,abcd'</code>. Clearly the <code>begin</code> index and <code>end</code> index change as the loop iterates—<code>(0,1),(1,2),(2,3),(3,4)</code>. That's fine and I can print: <code>'a,b,c,d'</code>. But how do I control it such that it will go from that to <code>(0,2),(1,3),(2,4)</code> and then <code>(0,3),(1,4),</code> and finally <code>(0,4)</code>? This is where I am stumped. Thanks for the assistance and here's my code:</p>
  
  <pre><code>void printSubstring()
  {
      int len = s.length();
  
      for (int i=0;i&lt;len;i++)
      {
          for (int k=0;k&lt;len;k++)
             System.out.print(s.substring(k,k+1)+", "); 
      }
      System.out.println();
  }
  </code></pre>