title: How do i break out of a loop when the user types in a specific string?
body: <p>I am trying to create two queues. One queue that holds a list of male names. And another queue holding a list of female names. The user has to type in a gender type before the name. So the program is supposed to know which queue the name goes into by an "m" or an "f". When I am typing in "m bob" or "f jill" and hit enter. It prints out the statement twice. Also when i type in "x done" it doesnt break out and print out the two lists.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class UsesArrayBndQueue {
    public static void main(String[] args)
    {
      ArrayUnbndQueue&lt;String&gt; test = new ArrayUnbndQueue&lt;String&gt;();
      ArrayUnbndQueue&lt;String&gt; test2 = new ArrayUnbndQueue&lt;String&gt;();
      boolean NotFull = false;
      Scanner scan = new Scanner(System.in);
  
     while(true)
      {
        System.out.println("Input a gender and a name (x done to quit):");
       String str1 = scan.next();
        if(str1.contains("x done")){
            break;
        }
       else if(str1.contains("m")){
           test.enqueue(str1);
        }
        else if(str1.contains("f")){
            test2.enqueue(str1);
        }
     }
  
    while (!test.isEmpty())
      {
        try
        {
          String str1 = test.dequeue();
          System.out.println(str1);
          String str2 = test2.dequeue();
          System.out.println(str2);
  
        }
        catch(QueueUnderflowException Except)
        {
          System.out.println(Except.getMessage());
        }
      }
    }
  </code></pre>
  
  <p>}</p>