# for loop question

• Beginner
• Joined: Feb 17, 2004
• Posts: 38
• Status: Offline

February 17th, 2004, 6:50 pm

I'm trying to get 2 loops to concatenate in parallel and can't do it!
to make it clearer here is my code:

Code: [ Select ]
conc = new Array(50, 10, -10, -50, -90);

for (j=7; j<40; j=j+7) {
for(h=0; h<5; h++){
_root["balls"+j]._x = conc[h];
....
1. conc = new Array(50, 10, -10, -50, -90);
2. for (j=7; j<40; j=j+7) {
3.   for(h=0; h<5; h++){
4.   _root["balls"+j]._x = conc[h];
5. ....

i'm guessing that since the h loop is nested in the j loop, during every looping session for 1 element or the j loop all the elements in the h loop are activated.
i need them to loop in parallel so for each 1j there is an 1h at every looping session instead of for each 1j there are 5h.

i tried so many ways, i'm giving up soon. i'm sure it's right under my nose. but i already see double....

anybody???
thnx
• Anonymous
• Bot
• Joined: 25 Feb 2008
• Posts: ?
• Loc: Ozzuland
• Status: Online

February 17th, 2004, 6:50 pm

• stinger
• Joined: Jan 22, 2004
• Posts: 157
• Loc: San Jose, CA
• Status: Offline

February 18th, 2004, 12:42 am

Dont ever give up.

When you use the for loop. . . . . you are essentially stopping everything that is happening and executing your FOR.

so. . .

Code: [ Select ]
for(i=0; i<10; i++)
{
print("i");
}
1. for(i=0; i<10; i++)
2. {
3. print("i");
4. }

this will concecutively count from 0 to 9 printing i everystep of the way.

Now. . . .when you nest these FOR loops within eachother you are doing the same thing. However, my quickest analogy for what is happening is to imagine a file cabinet. in the file cabinet is folders.

Your first for loop, counts or goes through all the folders.
your second for loop will go through all the files in a folder.

Code: [ Select ]
for(i=0; i<10; i++)
{
for(j=0; j<10; j++)
{

}
}
1. for(i=0; i<10; i++)
2. {
3.     for(j=0; j<10; j++)
4.         {
5.         }
6. }

OK. . . I'll break this down. referencing a file cabinet.
the first for loop using I opens the file cabinet and runs through 10 folders.
when i=0, it will then loop 10 times doing the FOR j loop. or will count through 10 files. Then it runs the for I loop again. Moving to the next folder.. . . . I have a better example now. Lets run a simple counter.

Code: [ Select ]
for(i=0; i<3 i++)
{
for(j=0; j<3 j++)
{
print(j);
}
print(i);
}
1. for(i=0; i<3 i++)
2. {
3.     for(j=0; j<3 j++)
4.         {
5.         print(j);
6.         }
7. print(i);
8. }

THIS CODE WILL PRINT OUT THE FOLLOWING.

012
0
012
1
012
2

the 012 is the j var looping through the for loop.
the 0 is the i var being printed.
then 012 for j because it runs the loop again.
then 1 is the i var printed
etc. . . this will repeat as many times as declared.

NOW, I AM NOT QUITE SURE WHAT YOU ARE LOOKING FOR?????
are you trying to move a object in flash by looping through coords?
Or are you trying to concatenate the "balls" with your number?
when you concatenate something, you are combining them into one string. So you would have to change ther var type and use a separte variable.

If for every time that your var i exists, you only want 1 h var to exist, why are you using a for loop for your h? Can you not just declare a single variable within the original loop?

Also, you may want to try to embed your coding into a movie clip, and then use the looping of that movie clip to constantly update your variables.. . . .

Hope I have helped in some degree. If I had a better example of your desired effect, I could perhaps be more precise in my explanation/theory.

Good luck
• Beginner
• Joined: Feb 17, 2004
• Posts: 38
• Status: Offline

February 18th, 2004, 8:22 am

thank you stinger.
your explanation was magnificent. very clear! I understand loops forever.
I realized that i really didn't need too loop the h. it's just that i kept thinking that i have to go through the array, and how else will i do it. well, i realized i can assign single var instead of a for loop for the h value.

thanks again.

## Post Information

• Total Posts in this topic: 3 posts
• Users browsing this forum: No registered users and 71 guests
• You cannot post new topics in this forum
• You cannot reply to topics in this forum
• You cannot edit your posts in this forum
• You cannot delete your posts in this forum
• You cannot post attachments in this forum

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.