From: mental@... Date: 2005-12-08T02:51:42+09:00 Subject: Re: increasing counter whithin loop? Quoting Patrick Gundlach : > This is why I thought > > for i in sequence > if sequence[i]=='b' and sequence[i+1]=='b' > output 'double b' > # increase i, so that the second 'b' won't be seen by the > for-loop > # but ruby won't let me!? > # i += 1 does nothing > else > output sequence[i] > end > end > > would work, but I can't change the i in the for-loop. This is a > pity! It's probably helpful to realize that Ruby has no for-loop in the traditional sense. The above is equivalent to: sequence.each do |i| if sequence[i]=='b' and sequence[i+1]=='b' output 'double b' # increase i, so that the second 'b' won't be seen by the for-loop # but ruby won't let me!? # i += 1 does nothing else output sequence[i] end end Written this way, it's probably more obvious why incrementing i doesn't do what you had expected. -mental