title: While Loop in C# with Switch Statement
body: <p>I am trying to loop the switch condition if the choice is out of range. But i am not getting the desired output. So if while going through the switch condition the user does not input 1-3 as input, i want it to go to default condition which should trigger the error statement and then keep looping</p>
  
  <pre><code>Console.WriteLine("Which book would you like to check out?");
  Console.WriteLine("select 1 for book 1, 2 for book 2, and 3 for book 3");
  
  int choice=Convert.ToInt32(Console.ReadLine());
  
  bool loopBreak = true;
  while (true)
  {
      switch (choice)
      {
  
          case 1:
              Console.WriteLine("You have chosen book 1 {0}", b1.name);
              b1.CheckinCheckout = false;
  
              break;
  
  
          case 2:
              Console.WriteLine("You have chosen book 2 {0}", b2.name);
              b2.CheckinCheckout = false;
  
              break;
  
          case 3:
              Console.WriteLine("You have chosen book 3 {0}", b3.name);
              b3.CheckinCheckout = false;
  
              break;
          default:
              Console.WriteLine("Please enter a valid choice.");
              loopBreak = false;
              break;
      }
      if (loopBreak != false)
      {
  
          break;
      }
  }
  </code></pre>
  
  <p>Updated:</p>
  
  <pre><code>bool loopBreak=true;
  while (loopBreak==true)
  {
      Console.WriteLine("Which book would you like to check out?");
      Console.WriteLine("select 1 for book 1, 2 for book 2, and 3 for book 3");
      int choice = Convert.ToInt32(Console.ReadLine());
      switch (choice)
      {
  
          case 1:
              Console.WriteLine("You have chosen book 1 {0}", b1.name);
              b1.CheckinCheckout = false;
  
              break;
  
  
          case 2:
              Console.WriteLine("You have chosen book 2 {0}", b2.name);
              b2.CheckinCheckout = false;
  
              break;
  
          case 3:
              Console.WriteLine("You have chosen book 3 {0}", b3.name);
              b3.CheckinCheckout = false;
  
              break;
          default:
              Console.WriteLine("Please enter a valid choice.");
              loopBreak = false;
              break;
      }
      break;
  }
  </code></pre>