From: Paul Brannan Date: 2002-11-19T11:26:23+09:00 Subject: Re: ruby-dev summary 18711-18810 On Tue, Nov 19, 2002 at 08:48:01AM +0900, Yukihiro Matsumoto wrote: > Internal iterator is far simpler, and as powerful as external > iterator, except for parallel iteration. I won't buy complexity for > rarely used parallel iteration. They are useful for more than just parallel iteration; they are also useful for complex iteration (e.g. I move to the next element when a particular event occurs). In C++ I might write: int a[] = { 1, 2, 3, 4, 5 }; std::vector v(a, a + 5); std::vector::iterator it = v.begin(); while(it != v.end()) { std::cout << *it << std::endl; if(*it == 3) { it = v.erase(*it); } else { ++it; } } which produces: 1 2 3 4 5 but my naive solution in Ruby doesn't work: a = [1, 2, 3, 4, 5] a.each_with_index do |x, idx| puts x if x == 3 then a.delete_at(idx) end end (it skips the 4). Or is there a better way to write this that I am missing? Paul