Title: Use break and continue statements effectively.
Course: Java Programming (Oracle) (10055) > Section: Controlling Program Flow

Using break and continue statements should include transferring control out of one structure and into another. For example:

// Read input until a q is received.
class Break2 {
public static void main(String args[])
throws java.io.IOException {
char ch;
for( ; ; ) {
ch = (char) System.in.read(); // get a char
if(ch == 'q') break;
}
System.out.println("You pressed q!");
}
}

Employment of break and continue statements can also be with inner loops:

// Using break with nested loops.
class Break3 {
public static void main(String args[]) {
for(int i=0; i<3; i++) {
System.out.println("Outer loop count: " + i);
System.out.print("    Inner loop count: ");
int t = 0;
while(t < 100) {
if(t == 10) break; // terminate loop if t is 10
System.out.print(t + " ");
t++;
}
System.out.println();
}
System.out.println("Loops complete.");
}
}

NBEA Achievement Standards for Information Technology

Code common tasks (e.g., creating, adding, deleting, sorting, and updating records).