Skip to content

Break Statement

BreakStmt Entity

In Java, the break statement is used within loops (for, while, do-while) and switch statements to immediately terminate the execution of the current loop or switch block and transfer control to the statement following the terminated block. When encountered, it stops the current iteration and continues with the next one, bypassing any code that comes after the continue statement within the loop body. This is particularly useful when you want to skip specific iterations based on certain conditions while allowing the loop to continue its normal execution for other cases.

Example

for (int i = 0; i < 10; i++) {
if (i == 5) {
break; // BreakStmt
}
// Code to be executed for all iterations except when i is 5
}

Attributes

MethodDescription
GetAPrimaryQlClass() stringReturns the primary CodeQL class name for this entity
GetHalsteadID() intReturns the Halstead ID for this break statement
GetLabel() stringReturns the label associated with this break statement
hasLabel() boolChecks if the break statement has a label
GetPP() stringReturns the pretty-printed representation of the break statement
ToString() stringReturns the string representation of the break statement