Terminate the loop when the value of �i reaches 4.
for (int i = 0; i < 10; i++) { if (i == 4) { break; } System.out.println(i);}
i
out
The break keyword is used to break out a for loop, a while loop or a switch block.
break
for
while
switch
Exit a while loop prematurely using the “break” keyword.
int i = 0;while (i < 10) { System.out.println(i); i++; if (i == 4) { break; }}