title: Confuse with variable scope for while and for loop(C programming)
body: <p>Today while i was coding , I encounter something which I didn't expect it to happen in this way.Below is just an example code for the problem.</p>
  
  <p><b>The Code 1</b></p>
  
  <pre><code>while(true)
  {
   int i = 1;
  
   printf("This is %d\n" , i);
   ++i;
   if(i == 10)
     break;
  }
  </code></pre>
  
  <p><b>The Code 2</b></p>
  
  <pre><code>for(int i = 1 ; ; i++)
  {
   printf("This is %d\n" , i);
   if(i == 10)
      break;
  }
  </code></pre>
  
  <p><b>The Question :</b></p>
  
  <p>1.)The first code would causes infinite loop while the latter is not.</p>
  
  <p>2.)I don't understand , there's a standard mention variable declare inside while loop can be accessed by any statement inside the while loop , but why the <code>if()</code> can't access the value of variable i while the latter can??</p>
  
  <p><i>Thanks for spending time reading my question</i></p>