Not entirely sure you've given us enough information to solve this one. I'm not sure what you are trying to do.
It would be unusual to use while like this in Ruby. There are lots of better ways to iterate. For example, if you are walking through an array, you can do:
my_array.each do |e|
# e is the next element of my_array
end
If you are walking through a string, you can do:
my_string.each_char do |c|
# c is the next character in my_string
end
If you really want a counter, you can use each_with_index for an array, or for a string:
(1..my_string.size).each do |i|
c = my_string[i - 1]
# now c = next character, i = index
end
Not a direct answer to your question, I admit, but DJ & DigitalRoss are correct, you seem to be working towards nested loops.