# Two variables in a for loop

**URL:** <https://forum.kirupa.com/t/two-variables-in-a-for-loop/117357>\
**Category:** Uncategorized\
**Created:** [July 26, 2004, 9:24pm UTC](https://forum.kirupa.com/t/two-variables-in-a-for-loop/117357 "2004-07-26T21:24:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![emorej](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@emorej](https://forum.kirupa.com/u/emorej)\
**Post date:** [July 26, 2004, 9:24pm UTC](https://forum.kirupa.com/t/two-variables-in-a-for-loop/117357/1 "2004-07-26T21:24:55Z")

</div>

[font=Arial]Can anyone help with this; I have tried several ways but does not work.[/font]

[color=black][font=Arial]The first for loop creates the numbers to collect the correct tag in my xml file, that works, but I need a second variable in the for loop to select my random Array numbers [0][1][2][3]…[/font][/color]

here is the code, the code in red is the script im trying to work out

MyArray = [4, 5, 6, 7, 8];  
function shuffleArray() {  
return Math.round(Math.random());  
}  
myArray.sort(shuffleArray);  
for (var i = 4; i \< 9; i++; [color=red]var e = 0; e \< 5; e++)[/color][color=black]{[/color]  
[color=red]spread = myArray[e];[/color]

questionClip.attachMovie(“RandomAnswer”, “containeranswer”+i, i);  
questionClip[“containeranswer”+i].\_y = 0+((i\*15)-34);  
questionClip[“containeranswer”+i].\_x = 95;  
questionClip[“containeranswer”+i].ranAnswer = questionsArray[currentQuestion].[color=red]answers[spread];[/color]  
}

}

---

<div class="post-metadata">

**Author:** ![bodyvisual](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bodyvisual/32/564_2.png) [@bodyvisual](https://forum.kirupa.com/u/bodyvisual)\
**Post date:** [July 26, 2004, 9:30pm UTC](https://forum.kirupa.com/t/two-variables-in-a-for-loop/117357/2 "2004-07-26T21:30:51Z")

</div>

you could use dual for loops… one w/ i, one w/ e… you _are_ getting an error when you check your code, right?

:p:

---

<div class="post-metadata">

**Author:** ![emorej](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@emorej](https://forum.kirupa.com/u/emorej)\
**Post date:** [July 26, 2004, 9:40pm UTC](https://forum.kirupa.com/t/two-variables-in-a-for-loop/117357/3 "2004-07-26T21:40:59Z")

</div>

yea sure are getting an error, its doing my head in

---

<div class="post-metadata">

**Author:** ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)\
**Post date:** [July 26, 2004, 9:58pm UTC](https://forum.kirupa.com/t/two-variables-in-a-for-loop/117357/4 "2004-07-26T21:58:46Z")

</div>

> [@emorej](#):
>
> yea sure are getting an error, its doing my head in

gues you are trying to do a question/answer type thing. You might be better putting the questions/ answers in the same array and then shuffling it. Not sure exactly how you are making your movie but have a look at this.

---

<div class="post-metadata">

**Author:** ![bodyvisual](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bodyvisual/32/564_2.png) [@bodyvisual](https://forum.kirupa.com/u/bodyvisual)\
**Post date:** [July 26, 2004, 10:06pm UTC](https://forum.kirupa.com/t/two-variables-in-a-for-loop/117357/5 "2004-07-26T22:06:23Z")

</div>

the reason that you are getting an error message is b/c you can’t have 2 variables in a for loop.

:p:

---

<div class="post-metadata">

**Author:** ![kode](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@kode](https://forum.kirupa.com/u/kode)\
**Post date:** [July 27, 2004, 3:24pm UTC](https://forum.kirupa.com/t/two-variables-in-a-for-loop/117357/6 "2004-07-27T15:24:46Z")

</div>

You sure can have 2+ variables within the [font=courier new]for[/font] statement. 😉

```auto
for (var i = 4, e = 0; i<9; i++, e++) {
//do your stuff
}

```
