# Problem with For loop

**URL:** <https://forum.kirupa.com/t/problem-with-for-loop/224208>\
**Category:** flash\
**Created:** [April 30, 2007, 2:20am UTC](https://forum.kirupa.com/t/problem-with-for-loop/224208 "2007-04-30T02:20:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![drosa10](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@drosa10](https://forum.kirupa.com/u/drosa10)\
**Post date:** [April 30, 2007, 2:20am UTC](https://forum.kirupa.com/t/problem-with-for-loop/224208/1 "2007-04-30T02:20:58Z")

</div>

```auto

maxday = 30;
monthcodes = new Array(6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4);
calcday = function (currentday) {
    iyear = year-2000;
    iyear += Math.floor(iyear/4);
    correspondingcode = monthcodes[monthnum];
    iyear += correspondingcode;
    iyear += currentday;
    for (i=0; i<99; i++) {
        if (iyear>7) {
            iyear -= 7;
        } else {
            i = 5675;
        }
    }
    if (iyear == 7) {
        iyear = 0;
    }
    return iyear
};
rownum = 0;
columnnum = 0;
positionboxes = function () {
    for (i=1; i<maxday+1; i++) {
        _root["box"+i].date.text = i;
        _root["box"+i]._x = calcday(i)*110
    }
};
positionboxes();

```

the calcday function is just a function that calculates what day of the week and returns that in the form of a number from 0-6, where 0 = sunday, 1 = monday, etc. Nothing much to be concerned with. The real problem is inside the positionboxes function. The for loop works just fine if i remove the:

```auto
_root["box"+i]._x = calcday(i)*110

```

But, if I leave that peice of code inside the loop the loop will only run once. If I have ANY peice of code involving the calcday() functiion ive made, the loop will only run once. Why is the loop stopping when that happens but continues fine without it?
