From: "Gábor SEBESTYÉN" Date: 2005-06-20T23:31:09+09:00 Subject: Re: Iterate with condition --Apple-Mail-1--763269775 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed On 2005.06.20., at 14:10, Robert Klemme wrote: > What exactly do you want to do with the collection? > I want to get the first N pieces of "valid" objects from a =20 collection. I would iterate in collection counting how many objects =20 were sucessfully accepted and would break the cycle if there are no =20 more objects or I already have my N objects. Here's my solution =20 (written for Rails and the collection consists of ActiveRecord objects): cl =3D CustomerQueue.find(:all, :conditions =3D> cond, :order = =3D> =20 "created_at ASC") i =3D 0 while i < cl.size and n > 0 c =3D _openChat(cl[i].customer_id, @session[:user].id) unless c.nil? chats << c n =3D n - 1 end end I don't like referencing by index. That's why I asked you how to =20 implement this using iterator and not a simple while cycle with =20 indexing. G=E1bor "Never trust a computer you can't throw out a window." - Steve Wozniak --Apple-Mail-1--763269775--