title: Accessing and changing local variable inside while loop C#
body: <p>I am currently trying to define two integer variables by user input. If the user inputs an integer which is not contained in the defined range, the user will be asked to input again, until the user inputs an accepted value.</p>
  
  <pre><code>static void Main(string[] args)
  {
      int a;
      int b;
  
      bool isAValid = false;
      bool isBValid = false;
  
      while (isAValid == false)
      {
          Console.Write("Input number from 2 to 20: ");
          isAValid = true;
  
          a = Convert.ToInt16(Console.ReadLine());
  
          if (a &lt; 2 || a &gt; 20)
          {
              isAValid = false;
          }
      }
  
      while (isBValid == false)
      {
          Console.Write("Input number from 2 to 20: ");
          isBValid = true;
  
          b = Convert.ToInt16(Console.ReadLine());
  
          if (b &lt; 2 || b &gt; 20)
          {
              isBValid = false;
          }
      }
  }
  </code></pre>
  
  <p>What I am trying to accomplish, is saving the user input as <strong>a</strong> and <strong>b</strong> respectively, so the local variable value is defined as the user input value. However, when I try to access the local variable after the last while loop is broken, I get the "<em>Use of unassigned local variable <strong>a</strong> (or <strong>b</strong>)</em>". </p>
  
  <p>Any ideas how I can define the variables, while still having the input prompt loop?</p>