A
Alvaro Perez
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!!
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!!