Back to Intellij Community

IfStatementMissingBreakInLoop

java/java-impl/resources/inspectionDescriptions/IfStatementMissingBreakInLoop.html

2025.3-rc-2498 B
Original Source

Reports loops with an if statement that can end with break without changing the semantics. This prevents redundant loop iterations.

Example:

boolean found = false;
  for (int i = 0; i < arr.length; i++) {
    if (Objects.equals(value, arr[i])) {
      found = true;
    }
  }

After the quick-fix is applied:

boolean found = false;
  for (int i = 0; i < arr.length; i++) {
    if (Objects.equals(value, arr[i])) {
      found = true;
      break;
    }
  }

New in 2019.2