title: simplification of 2 if statements into a loop
body: <p>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 "<code>if (test1 or test2)</code>" and the second one is a test "<code>if (test1 and test2)</code>". </p>
  
  <p>Curently, to differentiate them, I have to put at a higher level (but still in the main loop) another "if" (test on <code>diagExpression boolean</code>, see below); here's the code :</p>
  
  <pre><code>// Main loop 
    while (Hit.arrayCurrent[Hit.coordCurrent[0]+k][Hit.coordCurrent[1]+l] == Hit.currentPlayer[1]) 
    {   
     if (diagExpression)
       {   
        if ((a &gt; b) || (b &gt; c))
          return;
        else if (d)
         {   
          //do stuff1
         }   
       }   
    else
      {   
       if ((a &gt; b) &amp;&amp; (b &gt; c))
          return;
       else if (d)
         {   
          //do stuff1
         }   
       }   
    }
  </code></pre>
  
  <p>I don't know how to do for simplifying this code snippet and avoiding to use the <code>stuff1</code> 2 times.</p>
  
  <p>If anyone could see a solution.</p>
  
  <p><strong>UPDATE :</strong></p>
  
  <p><code>diagExpression</code> is computed before the main loop : </p>
  
  <pre><code>// Boolean for 2 versions
    var diagExpression = false;
  
    if (Hit.direction == 'rightbottom')
      { 
        diagExpression = true;
        shift_x = 1;
        shift_y = 1;
        factor_x = 1;
        factor_y = 1;
        limit_x = 7;
        limit_y = 7;
      }
   else if (Hit.direction == 'left')
      {
        shift_x = -1;
        shift_y = 0;
        factor_x = -1;
        factor_y = 1;
        limit_x = 0;
        limit_y = -1;
      }
  
  ...
  
  // Main loop 
    while (Hit.arrayCurrent[Hit.coordCurrent[0]+k][Hit.coordCurrent[1]+l] == Hit.currentPlayer[1])
  </code></pre>
  
  <p>I use different directions values into my code and this boolean is true if I have diagonal directions and false for vertical/horizontal directions.</p>