title: Java Loops - Break? Continue?
body: <p>I've read through a bunch of threads on using <code>break</code> and <code>continue</code> and I suspect the problem isn't necessarily my use of those, but the layout of my loops. In the following code, I am trying to iterate through the chars in a string that is input by the user to find any <code>-</code> symbols.  If found, it will throw an error to the user that a negative number was found and exit. Otherwise, if it does not find a <code>-</code> symbol, it should print out all of the chars in the string.</p>
  
  <p>I used <code>break</code> at the end of my first loop to find the <code>-</code> symbol, but it is not continuing on to the next loop. I tried <code>continue</code> as well but that didn't work. Loops are new to me so I may have this completely wrong, all I know is my first loop is working OK and will throw the error when it finds a <code>-</code> in the string.</p>
  
  <pre><code>strNum1 = JOptionPane.showInputDialog ("Enter Number String");
  for (int i = 0; i &lt; strNum1.length(); i++) {
    char c = strNum1.charAt(i);
    if (c == '-') {
      System.out.println("Negative Digit Found - Exiting");
      break;
    }
  }
  
  for (int i = 0; i &lt; strNum1.length(); i++) {
    char c = strNum1.charAt(i);
    if (c &lt;= 9) {
      System.out.println(c);
    }
  }
  </code></pre>