# What is i?

Hey anyone,

Still learning AS, but one thing I still don’t understand is how that “i” thing works.

i always see i=0 and i++ and i<24, etc

what is it, how does it work, why the letter “i”?

You saw that from my ‘for loop’ on my sound object mini tutorial and I and a lot of people use ‘i’ for a default variable when counting in a loop…you can use anything, a letter, word, numder and so on, see:

``````for(i=1; i<24; i++) {
//If i is less than 24 then execute this code
//and add 1 to i every time the loop is executed
//until i is 24 or larger
}
``````

ok so i++ is like saying i+1?

if so, then I think I understand everything.

You hit the nail on the head, ummm…or something like that.

I is used as a counter in conjunction with loop statements. It can be used in endless amounts of ways as Iylamasse has demonstrated in many of his posts. It can be used to create very intricate code structures or it can be used for simpler things as well. A very good example which I have taken from the Actionscript:The Definitive Guide(Colin Moock, great book get it if you don’t have it already). This code is used to create a certain number of duplicated instances.

onClipEvent (enterFrame) {
for (i=1; i<=25; i++) {
duplicateMovieClip(first, “second” + i, i);
_root.first._y = random(300) + 1;
_root.first._x = random(300) + 1;
}
}

Hope this helps

Kyle

All of that definitely helped, Thanks everyone=)

I believe the reason programers have traditionaly used “i” is that it is not near either end of the chain of american letters. x y and z are all used to discribe locations in space… same thing with a b and c. Letters like m and r are used to represent various physics constants. So I think i is just a convienient letter that wasn’t being used for much of anything else. Course I’m just guessing.

Maybe it stands for International Variable…lol.