title: Sort entered number - difference between FOR and WHILE
body: <p>I have to write a code which sort digits in one entered number.</p>
  
  <p>For example: input: 4713239
               output: 1233479</p>
  
  <p>It doesn't work properly when I enter repeating digits(like 33) when I have the last loop as FOR:</p>
  
  <pre><code>for(int j = 0; j &lt; arr[i]; j++) // in this loop my output is: 123479.
  </code></pre>
  
  <p>When I change this loop from FOR to WHILE it works properly.
  It means:</p>
  
  <pre><code>while(arr[i]) // and the number is sorted correctly (1233479)
  </code></pre>
  
  <p>True be told, I don't know what is the difference between these operations in this code.</p>
  
  <p>Why FOR loop doesn't work properly? Could somebody explain me this? </p>
  
  <p>I wrote a code:</p>
  
  <pre><code>int sort(int arg)
  {
    int var, score = 0;
    int arr[10] = {0};
  
  
    for(int i = 0; i &lt; 10; i++)
      {
        var = arg % 10;
        arr[var]++;
        arg = arg / 10;
      }
  
  
    for(int i = 0; i &lt; 10; i++)
      {
        for(int j = 0; j &lt; arr[i]; j++) //while(arr[i]) --&gt; works correctly
      {
        score = score * 10 + i;
        arr[i]--;
      }
      }
    return score;
  }
  </code></pre>