Nested loop problem

Hello all, if you have a hint please help and you will be my hero, because I have been two days around this issue and I cannot figure it out.

I have nested loop in the following code that is not doing what I want. Please read the code and the comments to know what is all about.



for (var m:uint = 0; m< childrenArray.length; m++) {

                if (!this.contains( childrenArray[m])) 
                {
                    addChild(childrenArray[m]);
                    trace(childrenArray[m].name);
                    childrenArray[m].y=m*H;;
                } 
                
                else if (this.contains(childrenArray[m])) 
                           
                {
                      //The following loop does not work how I wish, but what I would like to do here is just remove all the elements in the cousinsArray from the stage, or at least the ones that are there.

                    for (var n:uint = 0; n< cousinsArray.length; n++) 
                    {
                    
                    removeChild(cousinsArray[n]);
                    
                    }

                }

            }

Hope there is a solution to this. Thank U!