break StatementPurpose:
- When executed in a
while,for,do-while, orswitchstructure, causes immediate exit from that structure.
Mechanics:
break;
Example:
for(int i=0; i<10; i++) {if (numA == 5) {break; // if the integer numA, is 5, break out of the for loop
}- /* other Java statement */
}
Usage:
- Common uses for the
breakstatement are to escape early from a loop, or to skip the remainder of a switch statement. - Execution continues with the first line of code after the structure.
email suggestions to: cs015tas@cs.brown.edu
