Inspectopedia Help

Early loop exit in 'if' condition

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

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023