From: David Alan Black Date: 2001-09-01T09:24:08+09:00 Subject: [ruby-talk:20650] Re: Iterating by links Hello -- On Sat, 1 Sep 2001, Joel VanderWerf wrote: > > This is part of an Enumerable extension package I'm going to submit to RAA > eventually, but it's useful, so maybe the ruby-list will forgive the size... > > Suppose you want to iterate over a linked list, or more generally a > sequence of objects that can be generated by iteratively calling some > function. You can do this by calling the function in a while loop. Or you > can use "by", as in these examples (source follows): I'm still playing around with this :-) but one possible source of problems is that you use a boolean test to end the series... which means, for example, that if you change this: > tree = [[0, [1, 2]], 3, [4, 5, [6]]] to this: tree = [[0, [1, 2]], 3, [4, 5, [6,7,nil]]] it will not process tree[2][2][2]. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav