1. Help create a function.

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?

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

Code:
```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:
//[...]
}
}```

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•