In Java, the break statement is used primarily to exit or terminate the loop in which it is used. It is often employed within loops (such as for, while, or do-while) and switch statements. Here's how break works in different contexts:
Loop Control:
for (int i = 0; i < 10; i++) {
if (i == 5) {
break; // Exit the loop when i equals 5
}
System.out.println(i);
}
In this example, when i becomes 5, the break statement causes the loop to terminate immediately.