From: Dominik Bathon Date: 2005-04-11T21:35:43+09:00 Subject: Re: [SOLUTION] Knight's Travails (#27) On Mon, 11 Apr 2005 06:49:37 +0200, Timothy Byrd wrote: >> Btw. does anybody know if this behavior is defined >> somewhere (adding elements to an Array while >> iterating over it): >> irb(main):001:0> (a=[0]).each { |i| a << i+1 if i < 10 }; a >> => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > If you just want to accumualte an array, here is a snippet from the > Programming Ruby HTML book: > > (1..10).to_a � [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Thanks for the reply, but that wasn't the intetion. While coding the solution, I first had something like this in my find_path method: front=[start] until front.empty? pos=front.shift all_moves(pos) { |m| if ... front << m end } end I experimented a bit and changed it to the following: (front=[start]).each { |pos| all_moves(pos) { |m| if ... front << m end } } It basicly does the same. And I wondered if this is "defined" behavior, or if it is just coincidence, that it works (adding elements to front, while iterating over it). Dominik