title: While loop not breaking when its condition isn't met
body: <p>The program should print "The number 11 occurs more than once"
  Then set duplicateFound to true and exit the while loop because it is true.
  But it prints "The number 13 occurs more than once" also.</p>
  
  <p>Why does this happen and how do I break the while loop so it does not keep going once the first duplicate (11) is found?
  This is an issue of efficiency as I only want to know if a duplicate exists.
  I don't care about how many.</p>
  
  <pre><code>public class DuplicateNumbers
  {
      public static void main(String[] name)
      {
          int[] myArray = { 64, 17, 9,  55, 2, 11, 11, 1,  8, 23, 13, 13};
          boolean duplicateFound = false;
          while (duplicateFound == false) 
          {
              for(int i = 0; i &lt; myArray.length; i++) 
              {           
                  for(int j = i + 1; j &lt; myArray.length; j++)
                  {
                      if(myArray[j] == myArray[i])
                      {
                          System.out.println("The number " + myArray[i] + " occurs more than once.");
                          duplicateFound = true;
                      }
                  }
              }
          }
          if(duplicateFound == false)
          {
              System.out.println("There are no duplicates.");
          }
          System.out.println("Array length is " + myArray.length);
      }
  }
  </code></pre>