title: Endless loop on nested while statement
body: <p>I am trying to utilize 2 while loops for a C# console program. The outer is to repeat the program menu and functions until the user exits. The inner loop I am using as validation of user input ( which needs to be parsed into an int).</p>
  
  <p>The inner loop seems to work fine but once program gets to the switch statement, it seems to loop the switch condition endlessly. So instead of write to console once I believe the outer while loop is making it write endlessly. Only case which sets flag to false stops as expected. </p>
  
  <p>Can someone explain what is happening? how would I update the flag so the outer while loop is not endlessly executing the functions in the switch? The program should go back to the user menu and await input in all cases except when user selects 7 to end program. I have been staring at this for hours. Please instruct me!</p>
  
  <pre><code>using System;
  using static System.Console;
  using System.Collections.Generic;
  
  namespace Project02AreaCalculator
  {
    class Program
    {
      static private bool flag = true;
      static void Main(string[] args)
      {
  
          string inputvalue = "";
          int caseSwitch;
  
          // repeat program until flag is set to false by user selecting 7 to exit
          do
          {
              // repeat menu until user input can be parsed into an integer
              while (!int.TryParse(inputvalue, out caseSwitch))
              {
                  flag = false;
                  Console.WriteLine("Shape Area Calculator");
                  Console.WriteLine("******************************************");
                  Console.WriteLine("\t1. Circle");
                  Console.WriteLine("\t2. Square");
                  Console.WriteLine("\t3. Rectangle");
                  Console.WriteLine("\t4. Rhombus");
                  Console.WriteLine("\t5. Parallelogram");
                  Console.WriteLine("\t6. Trapezoid");
                  Console.WriteLine("\t7. Exit");
                  Console.WriteLine("******************************************");
                  Console.WriteLine("Select a shape type to calculate");
                  inputvalue = ReadLine();
              }
  
              //convert input to integer and assign to caseSwitch
              caseSwitch = Convert.ToInt32(inputvalue);
  
              switch (caseSwitch)
              {
                  case 1:
                      CalculateCircle();
                      //Clear();
                      flag = true;
                      break;
                  case 2:
                      CalculateSquare();
                      // Clear();
                      flag = true;
                      break;
                  case 3:
                      CalculateRectangle();
                      //Clear();
                      flag = true;
                      break;
                  case 4:
                      CalculateRhombus();
                      //Clear();
                      flag = true;
                      break;
                  case 5:
                      CalculateParallelogram();
                      //Clear();
                      flag = true;
                      break;
                  case 6:
                      CalculateTrapezoid();
                      //Clear();
                      flag = true;
                      break;
                  case 7:
                      //Clear();
                      Console.WriteLine("Goodbye! Press any key to end");
                      ReadKey();
                      flag = false;
                      break;
                  default:
                      // Clear();
                      Console.WriteLine("Invalid Selection, Select 1-7");
                      flag = true;
                      break;
              }
  
  
          } while (caseSwitch != 7);
  
      }//end main
  
          //****************METHODS SECTION ****************************************************************************
          static private void CalculateCircle()
          {
              //area = pi * radius * radius (or pi times radius squared)
              Console.Clear();
              Console.WriteLine("Circle Area Calculator");
              Console.WriteLine("Enter the length of the circle's radius (-1 to exit back to menu):");
              Console.ReadKey();
  
          }
          static private void CalculateSquare()
          {
              //area = side * side (or side squared)
              Console.Clear();
              Console.WriteLine("Square Area Calculator");
              Console.WriteLine("Enter the length of one side of the square (-1 to exit back to menu):");
              Console.ReadKey();
            }
          static private void CalculateRectangle()
          {
              //area = Length * Width
              Console.Clear();
              Console.WriteLine("Rectangle Area Calculator");
              Console.WriteLine("Enter the length of one side of the Rectangle (-1 to exit back to menu):");
              Console.WriteLine("Enter the length of an opposing side of the Rectangle (-1 to exit back to menu):");
              Console.ReadKey();
          }
  
          static private void CalculateRhombus()
          {
              //area = ½ a * b (a and b being diagonals)
              Console.Clear();
              Console.WriteLine("Rhombus Area Calculator");
              Console.WriteLine("Enter the length of one diagonal of the rhombus (-1 to exit back to menu):");
              Console.WriteLine("Enter the length of the other diagonal of the rhombus (-1 to exit back to menu):");
              Console.ReadKey();
           }
          static private void CalculateParallelogram()
          {
              //area = base * height
              Console.WriteLine("Parallelogram Area Calculator");
              Console.WriteLine("Enter the length of the base of the Parallelogram (-1 to exit back to menu):");
              Console.WriteLine("Enter the height of the Parallogram (-1 to exit back to menu):");
              Console.ReadKey();
           }
  
          static private void CalculateTrapezoid()
          {
              //area = ½ height * (largeBase + smallBase)
              Console.WriteLine("Trapezoid Area Calculator"); 
              Console.ReadKey();
           }
      }
  }
  </code></pre>