From: Patrick Gundlach Date: 2005-12-12T21:07:38+09:00 Subject: Re: increasing counter whithin loop? Hi mental, [...] Your two solutions are very nice, thank you. I think I'll go for the each_with_next. > What's the actual problem you're trying to solve? I'll bet there's a > more "outside the box" solution. I have to print out some schedule. I create the parts by having a new specialized class parse some xml source, do some calculation and then output each. Let's say, one part of this schedule is a list of members. So I have class ListOfMembers def parse(src) # .... end def render # .... end end There are other items in the schedule that I need to output. I collect all these parts in an array: @schedule << ListOfMember.new.parse(the source) .... and output all like @schedule.each { |elt| elt.render } but in case of two 'ListOfMembers' following each other, they should be output next to each other, so I wrap them in a 'Group of two ListOfMembers' This is why I want to have a lookahead and a skip_next element to skip the second 'ListOfMembers' if the first one is already one of those and pass both to 'render two LOM'. It would have been easy in for i in 0...schedule.size if schedule[i]==LOM && schedule[i+1]==LOM # do the two LOM thing i += 1 else schedule[i].render end end Your ArrayStream looks very much like that, I begin to like it! Thanks for your answer, Patrick