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

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.16690

Last modified: 29 April 2024