title: Unsigned integers in C++ for loops
body: <p>I have made some research on Stackoverflow about reverse for loops in C++ that use an unsigned integer instead of a signed one. But I still do NOT understand why there is a problem (see <a href="https://stackoverflow.com/questions/5458204/unsigned-int-reverse-iteration-with-for-loops">Unsigned int reverse iteration with for loops</a>). Why the following code will yield a segmentation fault?</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  int main(void)
  {
      vector&lt;double&gt; x(10);
  
      for (unsigned int i = 9; i &gt;= 0; i--)
      {
          cout &lt;&lt; "i= " &lt;&lt; i &lt;&lt; endl;
          x[i] = 1.0;
      }
  
      cout &lt;&lt; "x0= " &lt;&lt; x[0] &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>I understand that the problem is when the index i will be equal to zero, because there is something like an overflow. But I think an unsigned integer is allowed to take the zero value, isn't it? Now if I replace it with a signed integer, there is absolutely no problem.</p>
  
  <p>Does somebody can explain me the mechanism behind that reverse loop with an unsigned integer?</p>
  
  <p>Thank you very much!</p>