# About for()

**URL:** https://forum.kirupa.com/t/about-for/183727
**Category:** flash
**Created:** [March 29, 2006, 3:56pm UTC](https://forum.kirupa.com/t/about-for/183727 "2006-03-29T15:56:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bohner](https://avatars.discourse-cdn.com/v4/letter/b/54ee81/32.png) [@Bohner](https://forum.kirupa.com/u/Bohner)
#### Post date: [March 29, 2006, 3:56pm UTC](https://forum.kirupa.com/t/about-for/183727/1 "2006-03-29T15:56:57Z")

</div>

Does the ‘for’ loop, loses it’s variables and/or results, as function() does when finished? If so …

Lets say I have a function that accepts two parameters, and returns one, and I want to save the values of numorus results in variables, so logicly I create a for loop, and save it to an array. But here’s the problem, I think that the array gets lost when the for loop ends, because after the ending }; the array doesn’t exist anymore.

Or am I doing something wrong again? : /

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [March 29, 2006, 4:01pm UTC](https://forum.kirupa.com/t/about-for/183727/2 "2006-03-29T16:01:37Z")

</div>

no, not in the same way as functions (unless used in a function, then it abides by the behavior of that functions variables).

Show what you have for code and we might be able to pinpoint the problem

---

<div class="post-metadata">

### Author: ![Bohner](https://avatars.discourse-cdn.com/v4/letter/b/54ee81/32.png) [@Bohner](https://forum.kirupa.com/u/Bohner)
#### Post date: [March 29, 2006, 4:08pm UTC](https://forum.kirupa.com/t/about-for/183727/3 "2006-03-29T16:08:55Z")

</div>

```auto

tMonth = new Array();
tMonth = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
tMonthDays = new Array();
tMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
mConstruct = function (d:Number, tabname:Array):Array {
	for (i = 0; i < tMonthDays[d]; i++) {
		tabname* = i + 1;
	}
	return tabname;
};

run = function () {
	for (j = 0; j < tMonth.length; j++) {
		monthName = tMonth[j];
		monthName = new Array();
		return mConstruct(j, monthName);
	}
};
a = run();
trace(a);

```

The part till the run(); function is done by the help of mathew.er from this [http://www.kirupa.com/forum/showthread.php?t=213890](http://www.kirupa.com/forum/showthread.php?t=213890) topic that I’ve created a while ago.

The code was ok, but I wanted to enchance it further, so that I wont have to write mConstruct(0, jan); mConstruct(1, feb); x12 to create arrays that I can later access. I know that I could make this far much simpler and faster, but I want to learn flexible scripting, not hardcoding data in the code.

---

<div class="post-metadata">

### Author: ![B\_L\_U\_E](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@B\_L\_U\_E](https://forum.kirupa.com/u/B_L_U_E)
#### Post date: [March 29, 2006, 5:26pm UTC](https://forum.kirupa.com/t/about-for/183727/4 "2006-03-29T17:26:30Z")

</div>

> [@Bohner](#):
>
> The code was ok, but I wanted to enchance it further, so that I wont have to write mConstruct(0, jan); mConstruct(1, feb); x12 to create arrays that I can later access.

So the code does work. What exactly is your question then? To simplify the code even further? because its already pretty modular…

---

<div class="post-metadata">

### Author: ![Bohner](https://avatars.discourse-cdn.com/v4/letter/b/54ee81/32.png) [@Bohner](https://forum.kirupa.com/u/Bohner)
#### Post date: [March 29, 2006, 9:36pm UTC](https://forum.kirupa.com/t/about-for/183727/5 "2006-03-29T21:36:00Z")

</div>

The code up to run() works. Run as is doesn’t work as it supposed to. The function should create 12 arrays accessible from \_root. But I can’t access them from enywhere else than the run function itself.
