Java break statement:
- The break statement is used to terminate a statement sequence in a switch statement.
- This statement is used to exit a loop. That means when a break statement is encountered inside a loop, the loop is terminated and program control resumes at the next statement following the loop.
Here is a simple example to use break statement:
public static void main(String args)
break; //terminate loop if i is 2
System.out.println("end of loop");
end of loop