# Nested loop problem

**URL:** https://forum.kirupa.com/t/nested-loop-problem/290111
**Category:** Uncategorized
**Created:** [June 9, 2009, 10:54pm UTC](https://forum.kirupa.com/t/nested-loop-problem/290111 "2009-06-09T22:54:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![andriusain](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andriusain](https://forum.kirupa.com/u/andriusain)
#### Post date: [June 9, 2009, 10:54pm UTC](https://forum.kirupa.com/t/nested-loop-problem/290111/1 "2009-06-09T22:54:40Z")

</div>

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.

```php

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!
