# \[AS2|F8\]Changing the way a For Loop counts

**URL:** <https://forum.kirupa.com/t/as2-f8-changing-the-way-a-for-loop-counts/210726>\
**Category:** flash\
**Created:** [December 21, 2006, 12:53pm UTC](https://forum.kirupa.com/t/as2-f8-changing-the-way-a-for-loop-counts/210726 "2006-12-21T12:53:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![waywoodr](https://avatars.discourse-cdn.com/v4/letter/w/3be4f8/32.png) [@waywoodr](https://forum.kirupa.com/u/waywoodr)\
**Post date:** [December 21, 2006, 12:53pm UTC](https://forum.kirupa.com/t/as2-f8-changing-the-way-a-for-loop-counts/210726/1 "2006-12-21T12:53:54Z")

</div>

I know that

```auto
for (var i = 0; i<5; i++)

```

will loop through some script adding 1 to i until i equals 5

but i was wondering if i could change the script from counting 1, 2, 3 etc.  
to 001, 002, 003, … , 042, 043, … , 121, 122, etc. So that there is always 3 didgets

the reason being is that i want to load images in an xml photo gallery, but i want to work out the xml part so it will load images 001.jpg, 002.jpg etc. into the gallery up until a certain number. (because I have a lot of images, and lots of galleries, and im lazy 😛 )

I was thinking of doing

```auto
if (i.length == 2) {
i = "0"+i;
};

```

and

```auto
if (i.length == 1) {
i = "00"+i;
};

```

but i don’t know if it will work

does anyone know if i have the right approch, or there is an easier way of doing it that I’m too ignorent to see??😃

(I was just about to say “■■■■ i wish this thing has spell check” … but wait … it does :stunned: You have thought of everything kirupa)
