title: Why does the while loop keep looping
body: <p>Why does the while loop keep looping when I declare flag false?
  Once I enter a correct input, the program should end.
  Any help would be greatly appreciated.
  New to java. 
  Many thanks everyone!</p>
  
  <pre><code>import javax.swing.JOptionPane;
  import java.util.*;
  
  
  public class Project1Chang
  {
  public static void main(String[] args)
  {
      String name;
      String sex;
      int height;
      boolean flag = true;
  
      JOptionPane.showMessageDialog (null, "This program calculates tidal volume.", "Tidal Volume Calculator", JOptionPane.INFORMATION_MESSAGE);
  
      name = JOptionPane.showInputDialog("What is your name?");
      sex = JOptionPane.showInputDialog("What is your sex?");
  
      while (flag = true)
      {
          height = Integer.parseInt (JOptionPane.showInputDialog("What is your height? (48-84 inches or 114-213 centimeters) \nEnter whole numbers only."));
  
          if (height &lt;= 84 &amp;&amp; height &gt;= 48)
          {
              if (sex.equalsIgnoreCase("male") || sex.equalsIgnoreCase("m"))
              {
                  double malePbwInch = 50 + 2.3 * (height - 60);
                  JOptionPane.showMessageDialog(null, malePbwInch);
                  flag = false;
              }
          }
          else if (height &lt;= 213 &amp;&amp; height &gt;= 114)
          {
              if (sex.equalsIgnoreCase("male") || sex.equalsIgnoreCase("m"))
              {
                  double malePbwCm = 50 + .91 * (height - 152.4);
                  JOptionPane.showMessageDialog(null, malePbwCm);
                  flag = false;
              }
          }
          else
          {
              JOptionPane.showMessageDialog(null, "This is an invalid input. Try again.");
          }
      }
  }
  </code></pre>
  
  <p>}</p>