title: C++ use `const int` as looping variable?
body: <p>I want to write code that compiles conditionally and according to the following two cases:</p>
  
  <p>CASE_A:</p>
  
  <pre><code>    for(int i = 1; i &lt;= 10; ++i){
          // do something...
      }
  </code></pre>
  
  <p>CASE_B: ( == !CASE_A)</p>
  
  <pre><code>    {
          const int i = 0;
          // do something...
      }
  </code></pre>
  
  <p>That is, in case A, I want to have a normal loop over variable <code>i</code> but, in case B, i want to restrict local scope variable <code>i</code> to only a special case (designated here as <code>i = 0</code>).  Obviously, I could write something along the lines:</p>
  
  <pre><code>    for(int i = (CASE_A ? 1 : 0); i &lt;= (CASE_A ? 10 : 0); ++i){
           // do something
      }
  </code></pre>
  
  <p>However, I do not like this design as it doesn't allow me to take advantage of the <code>const</code> declaration in the special case B.  Such declaration would presumably allow for lots of optimization as the body of this loop benefits greatly from a potential compile-time replacement of <code>i</code> by its constant value.</p>
  
  <p>Looking forward to any tips from the community on how to efficiently achieve this.</p>
  
  <p>Thank you!</p>
  
  <p>EDITS:</p>
  
  <p>CASE_A vs CASE_B can be evaluated at compile-time.</p>
  
  <p><code>i</code> is not passed as reference</p>
  
  <p><code>i</code> is not re-evaluated in the body (otherwise <code>const</code> would not make sense), but I am not sure the compiler will go through the effort to certify that</p>