vendredi 1 mai 2015

Merge four loops 'for' in one with different inner methods

I have four almost same loops in Java with different methods:

int Point;
for (int i = 0; i < 10; i++)
{
    if (isLeft())
         Point = i;    
}

for (int i = 0; i < 10; i++)
{
    if (isRight())
         Point = i;
}

for (int i = 0; i < 10; i++)
{
    if (isAbove())
         Point = i;
}

for (int i = 0; i < 10; i++)
{
    if (isUnder())
         Point = i;
} 

Can I merge all loops to one?

Aucun commentaire:

Enregistrer un commentaire