Break & Continue in Java
Break
By using break,you can force immediate termination of a loop, bypassing the conditional expression and any remaininh code in the body of the loop.When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
Continue
The continue statement performs such an action. In while and do-while loops, a continue statement causes control to be transferred directly to the conditional expression that controls the loop.
Code Snippet
//Break & Continue in Java
public class App {
public static void main(String args[]) {
for (int i = 1; i <= 10; i++) {
if (i == 5)
continue;
System.out.println(i);
if (i == 8)
break;
}
}
}