# Can someone tell me how for loops work?

**URL:** <https://forum.kirupa.com/t/can-someone-tell-me-how-for-loops-work/298390>\
**Category:** flash\
**Created:** [October 18, 2009, 12:30am UTC](https://forum.kirupa.com/t/can-someone-tell-me-how-for-loops-work/298390 "2009-10-18T00:30:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![IQAndreas](https://avatars.discourse-cdn.com/v4/letter/i/f08c70/32.png) [@IQAndreas](https://forum.kirupa.com/u/IQAndreas)\
**Post date:** [October 18, 2009, 12:30am UTC](https://forum.kirupa.com/t/can-someone-tell-me-how-for-loops-work/298390/1 "2009-10-18T00:30:51Z")

</div>

Um… I think there is something I’m getting wrong. Theoretically, this should work, but it’s giving me some unexpected results:

```auto
var i:int;

for (init(); i < total(); addi())
{
    trace("In loop");
}

function init():void
{
    trace("First");
    i = 0;
}

var _total:int = 10;
function total():int
{
    trace("Second");
    return _total;
}

function addi():void
{
    trace("Third");
    i++;
}

```

Outputs:

```auto
First
Second

```

There should be a lot more! While changing the code to this works as expected:

```auto
for (init(); i < 10; addi())
{
    trace("In loop");
}

//The rest of the code is the same...

```

Outputs

```auto
First
In loop
Third
In loop
Third
...etc

```

Can anyone tell me what I’m doing wrong and why the for loop is acting in this way?

So, basically, a for loop is a “ **while** ” loop. Is there any builtin way (just easier to read instead of using negatives and working around it) to create an “ **until** ” loop?

[SIZE=1]EDIT: A funny note, three times in a row (not all at once) these forums yelled at me because all three tags “for”, “while”, and “until” were too common words to use as tags.:hugegrin:[/SIZE]
