# Confused with for loops, help would be appreciated

**URL:** <https://forum.kirupa.com/t/confused-with-for-loops-help-would-be-appreciated/230573>\
**Category:** Uncategorized\
**Created:** [June 27, 2007, 10:25am UTC](https://forum.kirupa.com/t/confused-with-for-loops-help-would-be-appreciated/230573 "2007-06-27T10:25:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![welshy](https://avatars.discourse-cdn.com/v4/letter/w/2bfe46/32.png) [@welshy](https://forum.kirupa.com/u/welshy)\
**Post date:** [June 27, 2007, 10:25am UTC](https://forum.kirupa.com/t/confused-with-for-loops-help-would-be-appreciated/230573/1 "2007-06-27T10:25:36Z")

</div>

Hi, I’m starting to experiment with for loops for the first time in flash. As practice I’ve got 5 images (named img1, img2 etc) and 5 buttons (btn1, btn2 etc). All the images are set visible false initially; they then appear with each corresponding button press (btn 1 shows img 1etc). The code I’ve used is

for (j=0; j\<5; j++) {  
\_root[“img”+j].\_visible = 0;  
\_root[“btn”+j].onPress = function() {  
\_root[“btn”+j].\_visible = 1;  
};  
}

I thought this code would work, but obviously it doesn’t, could anyone point out were I’m going wrong?  
Thank you kindly.
