title: C++ statement is ignored in function
body: <p>I have this test program and it seems like some statements inside a function (<code>gcd()</code>) are ignored. The <code>std::cout</code> statement seems to be ignored since nothing is printed to the screen with that statement. The <code>if</code> statement seems to be ignored because <code>a</code> and <code>b</code> were less than zero and <code>b</code> was positive whether that <code>if</code> statement was there or not (<code>a</code> and <code>b</code> remained the same).</p>
  
  <p>I can't figure out why. Why are the two statements marked (with comment) are ignored?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;boost/multiprecision/cpp_int.hpp&gt;
  
  template &lt;typename T&gt; T gcd(T a, T b)
  {
      T remainder{a % b};
      while (remainder != 0)
      {
          a = b;
          b = remainder;
          std::cout &lt;&lt; remainder &lt;&lt; '\n'; // ignored
          remainder = a % b;
      }
      if (a &lt; 0 &amp;&amp; b &lt; 0) b *= -1; // ignored
      return b;
  }
  
  int main(int argc, char* argv[])
  {
      if (argc != 3)
      {
          std::cerr &lt;&lt; '\n' &lt;&lt;
                       "Invalid number of argument(s)\n" &lt;&lt;
                       '\n' &lt;&lt;
                       "Usage: [number] [number]\n" &lt;&lt;
                       '\n';
          return -1;
      }
  
      boost::multiprecision::cpp_int a{0}, b{0};
      try
      {
          a = boost::multiprecision::cpp_int{argv[1]};
          b = boost::multiprecision::cpp_int{argv[2]};
      }
      catch (...)
      {
          std::cerr &lt;&lt; '\n' &lt;&lt;
                       "Invalid argument(s) or numbers too large/small\n" &lt;&lt;
                       '\n' &lt;&lt;
                       "Usage: [number] [number]\n" &lt;&lt;
                       '\n';
          return -1;
      }
  
      const boost::multiprecision::cpp_int vgcd = gcd(a, b); // call to gcd()
      std::cout &lt;&lt; '\n' &lt;&lt;
                   "GCD (Greatest Common Divisor) test program using Euclid's algorithm (iterative)\n" &lt;&lt;
                   '\n' &lt;&lt;
                   "GCD(a, 0) = a\n" &lt;&lt;
                   "GCD(a, b) = GCD(b, a % b)\n" &lt;&lt;
                   '\n' &lt;&lt;
                   "GCD = " &lt;&lt; vgcd &lt;&lt; "      Simplified fraction: " &lt;&lt; a / vgcd &lt;&lt; " / " &lt;&lt; b / vgcd &lt;&lt; '\n' &lt;&lt;
                   '\n';
  }
  </code></pre>