From: Venkat Surabhi Date: 2011-03-25T16:36:12+09:00 Subject: Re: break from select Thanks Saravanan for your reply. I thought of doing this . But the problem is array size. Here I defined array with 15 elements. What if we have 1000 of elements in array. Below code a.collect will iterate for all the elements even if I achieved 5 elements. Saravanan Krishnan wrote in post #989140: > Hi Venkat, > > Quick Solution, > a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] > b =[] > a.collect{|x| b << x if x %2 == 0 and b.length<5} > puts b.inspect > > Cheers, > Sarav > -- Posted via http://www.ruby-forum.com/.