Array index is out of range error, why?

Hi all!

My code is the following:

var horizontal :int[] = new int[5]; 
var i : int = 0;
Debug.Log(i);
while ( i < 5){
	horizontal *= (levelnum / 5);*

_ Debug.Log(horizontal*);_
_
++i;_
_
}_
_and i’m getting the “Array index is out of range error” error in line 9 which is (horizontal *= (levelnum / 5);) why? i just don’t get it, could someone explain it to me?.
Thanks in advance!_

Try using for:

var horizontal : int[] = new int[5]; 

for(var i : int = 0; i < 5; i++)
{
    Debug.Log(i);
    horizontal *= (levelnum / 5);*

Debug.Log(horizontal*);*
}