Bubble Sort in Ruby

#1

Hi guys, I’m new to programming and to Ruby in general and I was seeking help with understanding how bubble sort works. So an example I found started off with setting the variable sorted = false, then constructing a while loop that executes while !sorted. Sorted starts out as false, so how does the while loop execute with the not sorted(true) condition, when I initialized the variable to false?
here’s the snippet of my code
def bubble_sort
[4] pry(main)* sorted = false
[4] pry(main)* while !sorted
[4] pry(main)* sorted = true
[4] pry(main)* (0…self.length-1).each do |index|
[4] pry(main)* if self[index] > self[index+1]
[4] pry(main)* self[index],self[index+1] = self[index+1],self[index]
[4] pry(main)* sorted = false
[4] pry(main)* end
[4] pry(main)* end
[4] pry(main)* end
[4] pry(main)* self
[4] pry(main)* end