title: Sorting arrays (Bubble Sort)
body: <p>I have a small doubt while sorting arrays and yeah I am new to programming. Take a look at this code for example:</p>
  
  <pre><code>public void bubbleSort(int[] array) {
  boolean swapped = true;
  int j = 0;
  int tmp;
  while (swapped) {
      swapped = false;
      j++;
      for (int i = 0; i &lt; array.length - j; i++) {
          if (array[i] &gt; array[i + 1]) {
              tmp = array[i];
              array[i] = array[i + 1];
              array[i + 1] = tmp;
              swapped = true;
          }
      }
  }
  </code></pre>
  
  <p>In the above code, why do we have to use <code>j++</code> and <code>i &lt; (array.length-j)</code> as the test expression? We could have rather used <code>i &lt; (array.length)</code> as the test expression while omitting the variable <code>j</code>. Any answers?</p>