title: Search Vertically and Horizontally in 2D Array
body: <p>Basically I want to do a search Horizontally, and also Vertically. Right now I am doing this:</p>
  
  <pre><code>void checkHorizontal()
  for (int iii = 1; iii&lt;Row;; iii++)
  {
      for (int jjj = 1; jjj&lt;Col; jjj++)      //for every col
      {
          if(Array[iii][jjj]==sign)
          {
              //do something
          }
          else
          {
              //do something else
          }
  
      }
  }
  
  void checkVertical()
  for (int iii = 1; iii&lt;Col;; iii++)
  {
      for (int jjj = 1; jjj&lt;Row; jjj++)      //for every row
      {
          if(Array[jjj][iii]==sign)
          {
              //do something
          }
          else
          {
              //do something else
          }
  
      }
  }
  </code></pre>
  
  <p>Yet, except the check function inside the for loop and the if statement, everything else is the same. And I want to reduce duplicate code, so what can I do to make a more generic function and caller just need to pass in saying if they want to do a Horizontal search or Vertical search (i.e. <code>void check(string mode)</code> and caller just <code>check("Vertical")</code>)</p>
  
  <p>I know I can get pass the check function inside the for loop by doing something like this:</p>
  
  <pre><code>if (mode == "Horizontal")
  {
      firstBoundary = cGameBoard.m_nRow;
      secondBoundary = cGameBoard.m_nCol;
  }
  else if (mode == "Vertical")
  {
      firstBoundary = cGameBoard.m_nCol;
      secondBoundary = cGameBoard.m_nRow;
  }
  void check(string mode)
  for (int iii = 1; iii&lt;firstBoundary;; iii++)
  {
      for (int jjj = 1; jjj&lt;secondBoundary; jjj++)     
      {
          if(Array[jjj][iii]==sign)
          {
              //do something
          }
          else
          {
              //do something else
          }
  
      }
  }
  </code></pre>
  
  <p>the problem is the if statement, don't know the best way of swapping the array except doing a function call to do it.
  My proposal:</p>
  
  <pre><code>bool if(string mode, int&amp; iii, int &amp;jjj, array,string sign)
  {
      if(mode=="Horizontal")
          return array[iii][jjj]==sign;
      else if(mode=="Vertical")
          return array[jjj][iii]==sign;
  }
  </code></pre>
  
  <p>And call this function inside if statement</p>