title: Please help me explain how to sort an array without using Array#sort Ruby
body: <p>The bubble_sort method should accept an array of numbers and arrange the elements in increasing order. The method should return the array. I understand the swap part but don't really understand the flipping of true and false and the reason they're there at the first place. It would be great to explain it line by line to help me understand this.</p>
  <blockquote>
  <p>Do not use the built-in <code>Array#sort</code></p>
  </blockquote>
  <pre class="lang-rb prettyprint-override"><code>def bubble_sort(arr)
      sorted = false
  
      while !sorted
          sorted = true
          (0...arr.length-1).each do |i|
              if arr[i] &gt; arr[i+1]
                  arr[i], arr[i+1] = arr[i+1], arr[i]
                  sorted = false
              end
          end
      end
      arr
  
  end
  
  
  p bubble_sort([2, 8, 5, 2, 6])      # =&gt; [2, 2, 5, 6, 8]
  p bubble_sort([10, 8, 7, 1, 2, 3])  # =&gt; [1, 2, 3, 7, 8, 10]
  </code></pre>