title: How to write a while loop which is identical to for loop in c
body: <p>I've encountered strange behaviour while writing bubble sort in c.
  The code i wrote using for loop is (which is working as i thought),</p>
  
  <pre><code>int arr[] = {-1,3333,1,3,4,2,3,4,5,6,7,4,11,12,332,1,-11};
      int i,j;
      int size = sizeof(arr)/sizeof(arr[0]);
      print_array(arr,size);
      for(i=0;i&lt;size-1;i++)
          for(j=1;j&lt;size-i;j++)
              if(arr[j]&lt;arr[j-1])
                  swap(&amp;arr[j],&amp;arr[j-1]);
      print_array(arr,size);
  </code></pre>
  
  <p>which gives me the output:</p>
  
  <p>given array:  -1,3333,1,3,4,2,3,4,5,6,7,4,11,12,332,1,-11 </p>
  
  <p>sorted array: -11,-1,1,1,2,3,3,4,4,4,5,6,7,11,12,332,3333</p>
  
  <p>but when i rewrote the same bubble sort using while loops(not working as planned),</p>
  
  <pre><code>    int arr[] = {-1,3333,1,3,4,2,3,4,5,6,7,4,11,12,332,1,-11};
      int i=0,j=1;
      int size = sizeof(arr)/sizeof(arr[0]);
      print_array(arr,size);
      while(i&lt;size-1)
      {
          while(j&lt;size-i)
          {
              {
                  if(arr[j]&lt;arr[j-1])
                      swap(&amp;arr[j],&amp;arr[j-1]);
              }
              j++;
          }
          i++;
      }
      print_array(arr,size);
  </code></pre>
  
  <p>which gives output,</p>
  
  <p>given array:  -1,3333,1,3,4,2,3,4,5,6,7,4,11,12,332,1,-11 </p>
  
  <p>sorted array: -1,1,3,4,2,3,4,5,6,7,4,11,12,332,1,-11,3333 </p>
  
  <p>what am i missing ? (i am using gcc comiler in linux).</p>