From: "Jan E." Date: 2012-06-11T07:25:54+09:00 Subject: Re: Beginner question: Bubble sort using array.each_index Hi, You misunderstand the code. "first" and "second" aren't fixed values. They are the block parameters belonging to the two iterators, so their value will change on each iteration. Have a look at the outer iterator first: array.each_index do |first| end This iterator loops over the indices of "array". On each iteration, the current index is assigned to the "first" parameter. So if array is ['x', 'z', 'y'] for example, the parameter will be assigned the values 0, 1 and 2 subsequently. You can test this: array.each_index do |first| puts first end Then there is also an inner iterator, which also loops over the indices of array. This means: While the outer iterator is going through the indices 0, 1, 2, 3, ..., the inner iterator will do the same on every step. See for yourself: array.each_index do |first| array.each_index do |second| puts "first (outer): #{first}, second (inner): #{second}" end end By the way, the code you posted is *not* bubble sort. I do not even know it, but it is definitely a bad algorithm, since it involves a lot of unnecessary element swapping. -- Posted via http://www.ruby-forum.com/.