For loop question

Hello,

I have a question for using the for loop

I have this code running and it’s doing perfectly fine

for (i = 0; i <= 20; i ++){
newMovieName = “movie” + i;
this[newMovieName].gotoAndPlay(“start”);
}

what if I want all 21 movies to play except for lets us movie number 7? Is there a way to ask the for loop to skip 7? Thanks!!!

Loc

The “for” statement doesn’t actually have a function for emitting values. You could miss out the number seven by using an additional “if” statement to check it 7 is the current number in the for loop or not. Try using this code…

for (i = 0; i <= 20; i ++){
if (i != 7) {
newMovieName = "movie" + i;
this[newMovieName].gotoAndPlay("start");
}
}

See how it works? If “i” is not equal to seven then it executes your code, otherwise it does nothing and moves onto the next loop (where i equals 8).

Hope this helps,
Dave

Except in this case you want to set if i != 6 since your loop starts at 0 and you want to not play movie #7. :wink: