# Why doesn't this work? (Complex, while loop with depths)

**URL:** <https://forum.kirupa.com/t/why-doesnt-this-work-complex-while-loop-with-depths/200769>\
**Category:** flash\
**Created:** [September 14, 2006, 11:44pm UTC](https://forum.kirupa.com/t/why-doesnt-this-work-complex-while-loop-with-depths/200769 "2006-09-14T23:44:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Z11](https://avatars.discourse-cdn.com/v4/letter/z/97f17d/32.png) [@Z11](https://forum.kirupa.com/u/Z11)\
**Post date:** [September 14, 2006, 11:44pm UTC](https://forum.kirupa.com/t/why-doesnt-this-work-complex-while-loop-with-depths/200769/1 "2006-09-14T23:44:17Z")

</div>

I have been working on this… and It is causing all my lag problems… But I kinda just left it until now… Since this is my first flash program… I figure I would wait it out until I got smarter… but a month later I’m still not figureing this one out…

dpd is generally 0 1 2 or so… but sometimes can get in the 20 range… when that happens, lag fest…

```auto

            while(dpd-- > 0)
                {

                for(var aa in arrayname)
                    {
                    var bb = arrayname[aa].getDepth()-505;
                    arrayname[aa].swapDepths(bb);
                    }//depth change loop

                }//ends the depth changing if

```

Basically put, it counts a number… dpd (i think it stands for depth difference) and then it runs the depth changing array how ever many times the depth was changed…

That doesn’t matter much… The problem is, the way it is… It works perfectly. However when I switch it to this… it stops working correctly (works but not correctly… the numbers go wild)

```auto

            if(dpd > 0)
                {

                for(var aa in arrayname)
                    {
                    var bb = arrayname[aa].getDepth()-(505*dpd);
                    arrayname[aa].swapDepths(bb);
                    }//depth change loop

                }//ends the depth changing if

```

In my opinion that whould work…

but it doesn’t I’ve placed trace everywhere, displaying various numbers, and it makes completly no sence what so ever… it’s as if the last one doesn’t remove any depth at all… And dpd isn’t ever 0, which would explain that… help
