title: Variables retain their value in a loop?
body: <p>If I run this simple code in a console app:</p>
  <pre><code>For i As Integer = 1 To 10
      Dim s As String = i.ToString()
      Dim x As Decimal
      If i = 1 Then
          x = Decimal.Parse(s)
      End If
      Console.WriteLine(x.ToString())
  Next
  Console.ReadLine()
  </code></pre>
  <p>Unexpectedly, <code>x</code> retains its value of 1 and so 1 gets printed 10 times. I thought each iteration of the loop was its own code block, and that the state didn't carry over? Why does this happen? I would expect <code>x</code> to have the default value of <code>System.Decimal</code>.</p>
  <p>Same thing happens in C#, except that the complier won't let you call <code>ToString()</code> on an uninitialized variable, but if you set a breakpoint in Visual Studio, you can see that <code>x</code> retains its value of 1.</p>
  <pre><code>for (int i = 1; i &lt;= 10; i++)
  {
      string s = i.ToString();
      Decimal x;
      if(i == 1)
      {
          x = Decimal.Parse(s);
      }
      // Value of x remains 1
  }
  Console.ReadLine();
  </code></pre>