title: c++ declaration and initialization variables inside while loops
body: <p>In the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      int num = 0;
  
      while (num &gt;= 0 &amp;&amp; num &lt;= 3)
      {
          int inner_loop_count = 0;
          cout &lt;&lt; "Loop # " &lt;&lt; ++inner_loop_count &lt;&lt; "\n";
          num++;
      }
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <blockquote>
    <p>Loop # 1<br>
    Loop # 1<br>
    Loop # 1<br>
    Loop # 1</p>
  </blockquote>
  
  <p>My understanding that the loop scope is between the braces {} and cannot be used to define a loop counter, because the declaration and the initialization will be redone each time.</p>
  
  <p>I tried the following solution:</p>
  
  <ol>
  <li>using static keyword. (Regardless of goodness or badness).</li>
  <li>including while itself inside outer {} and declare the counter variable there just right before while.</li>
  </ol>
  
  <p><strong>Question #1:</strong> Is my understanding correct?<br>
  <strong>Question #2:</strong> Are there any other -technically- possible solutions?</p>
  
  <p>Thanks</p>