mercredi 2 décembre 2015

simplification of 2 if statements into a loop

I would like to simplify a code snippet where I have one main loop in which I put 2 if statements. The first if statement is about a test "if (test1 or test2)" and the second one is a test "if (test1 and test2)".

Curently, to differentiate them, I have to put at a higher level (but still in the main loop) another "if" (test on diagExpression boolean, see below); here's the code :

// Main loop 
  while (Hit.arrayCurrent[Hit.coordCurrent[0]+k][Hit.coordCurrent[1]+l] == Hit.currentPlayer[1]) 
  {   
   if (diagExpression)
     {   
      if ((a > b) || (b > c))
        return;
      else if (d)
       {   
        //do stuff1
       }   
     }   
  else
    {   
     if ((a > b) && (b > c))
        return;
     else if (d)
       {   
        //do stuff1
       }   
     }   
  }

I don't know how to do for simplifying this code snippet and avoiding to use the stuff1 2 times.

If anyone could see a solution.

Aucun commentaire:

Enregistrer un commentaire