Help create a function

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


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:


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:

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?

You don’t need a function to shorten that code as a switch statement cal shorten it without needing a function call:

for(i=0;i<30;i++)
{
   switch(i) {
  case 1: case 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]++;
    break;
  //[...]
  default:
  //[...]
  }
}