Matakuliah Tahun Versi : M0074/PROGRAMMING II : 2005 : 1/0 MATERI PENDUKUNG JUMP 1 • The break statement The break statement will allow you to exit a loop structure before the test condition is met. Once a break statement is encountered, the loop immediately terminates, skipping any remaining code. For instance: int x = 0; 2 while (x < 10){ System.out.println("Looping"); x++; if (x == 5) break; else ... //do something else } In this example, the loop will stop executing when x equals 5. 3 • The continue statement The continue statement is used to skip the rest of the loop and resume execution at the next loop iteration. for ( int x = 0 ; x < 10 ; x++){ if(x == 5) continue; //go back to beginning of loop with x=6 System.out.println("Looping"); } • This example will not print "Looping" if x is 5, but will continue to print for 6, 7, 8, and 9. 4