# For..in vs for

**URL:** <https://forum.kirupa.com/t/for-in-vs-for/175004>\
**Category:** Uncategorized\
**Created:** [January 10, 2006, 11:41pm UTC](https://forum.kirupa.com/t/for-in-vs-for/175004 "2006-01-10T23:41:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sinister\_Shadow](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@Sinister\_Shadow](https://forum.kirupa.com/u/Sinister_Shadow)\
**Post date:** [January 10, 2006, 11:41pm UTC](https://forum.kirupa.com/t/for-in-vs-for/175004/1 "2006-01-10T23:41:07Z")

</div>

You would these two would work in a similar fashion right? Well I wasted over 4 hours yesterday because they don’t! :fight:

```auto
var randomArray:Array = new Array(10);
var numList:Array = new Array();
 
for (var i:String in randomArray)
 numList.push(i);

```

You would think tracing numList would output:

```auto
0, 1, 2, 3, 4, 5, 6, 7, 8, 9

```

Right?

Wrong! for…in seems to be a LIFO structure instead of a FIFO structure. It outputs the following:

```auto
9, 8, 7, 6, 5, 4, 3, 2, 1, 0

```

After 4 hours of confusion I resorted to using two for…in loops (one to get data and one to reverse the mess the first one makes). Today I decided to see if that’s the way a for loop works (because I was sure it didn’t) and when I got my answer I felt like personifying Flash and kicking it around!

:hitman:

Needless to say I have now converted all of my for…in loops to for loops.

Can someone please explain to me why the loops are different in such a way. Oh, the loops are being run from within an external class just in case it makes a difference.
