My question is how to make a function of this condition:

Code:
for(i=0;i<30;i++)
{
  if(i==0)
  {
    if(a[i].c<50) a[i].y--;
    else if(a[i].c>=50 && a[i].c<100) a[i].y++;
    else {a[i].c=0; a[i].y=65;}
    a[i]++;
  }
  //[...]
  else if(i==3)
  {
    if(a[i].c<50) a[i].y--;
    else if(a[i].c>=50 && a[i].c<100) a[i].y++;
    else {a[i].c=0; a[i].y=65;}
    a[i]++;
  }
   //[...]
}
I would like to shorten the code:
Code:
if(i==0) f(a[i].c,a[i].y);
//[...]
else if(i==3)  f(a[i].c,a[i].y);
I'm trying this:
Code:
function f(i,Y)
{
if(i<50) Y--;
else if(i>=50 && i<100) Y++;
else {i=0; Y=65;}
i++;
}
But it ds'not work.
How to do it correctly?