title: QuickSort code example . need a little clarification
body: <p>i am new to programming and java,  and i am trying to understand a code that implements the "quickSort" algorithem for sorting an array.<br>
  now..i understood the basic idea of quicksort, so the question is mainly about the code itself.<br>
  in the code below (the partition() method)   we have a main loop (while(i&lt;=j) ) and two loops inside and than another decision.     what i don't understand is what is the reason that the decision with the swap below the loops isn't being executed in every iteration of the main loop.       in simple words,after the last while loop (  while(arr[j]>pivot)  j--;)  why does the condition below doens't being execute?     they  do  j++ and than the code should move on outside of the loop isn't it?       as i understand from this example...it doen not!  </p>
  
  <p>here is the code i am talking about:  </p>
  
  <pre><code>public  class QuickSort {
  
      public static int list[] = {1,56,7,34,1,1,4,25,100,85,250};
  
      public static int partition(int arr[],int left,int right){
  
          int i = left;
          int j = right;
          int tmp;
          int pivot = arr[(left + right) / 2];
  
          while(i&lt;=j){
               while(arr[i]&lt;pivot){
                   i++;
               }
               while(arr[j]&gt;pivot){
                   j--;
               }
               if(i&lt;=j){
                   tmp = arr[i];
                   arr[i] = arr[j];
                   arr[j] = tmp;
                   i++;
                   j--;
               }
          }
          return i;
      }
  
  
      public static void quickSort(int arr[],int left,int right){
          int index = partition(arr,left,right);
          if(left&lt;index-1){
              quickSort(arr,left,index-1);
          }
          if(index&lt;right){
              quickSort(arr,index,right);
          }
      }
  </code></pre>