You can set a variable and set it true if you find. Then inside the loop, use it like this: if (find = true) break Or you can use exceptions to break the loop. 2007/11/19, Alvaro Perez <alvaro.pmartinez / gmail.com>: > Hi there, > > something that I think should not be very difficult, but i'm struggling > with: > > def find(name, where) > for father in where > if (father.name==name) then > found = thing > break > else > find(name, father.children) > end > end > found > end > > I have an array with parent objects, some of them have children. I want > to find an object with the same name and return in, otherwise nil. > > The problem is that, once I start searching inside the children of some > father, and I found what I'm looking for, I break the loop inside (array > father.children). But then the search continues in the level above. I > would like to break the complete search. How can it be done? > > Thank you!! > -- > Posted via http://www.ruby-forum.com/. > >