'for' loop may be replaced by 'while' loop
Reports for
loops that contain neither initialization nor update components, and suggests converting them to while
loops. This makes the code easier to read.
Example:
for(; exitCondition(); ) {
process();
}
After the quick-fix is applied:
while(exitCondition()) {
process();
}
The quick-fix is also available for other for
loops, so you can replace any for
loop with a while
loop.
Use the Ignore 'infinite' for loops without conditions option if you want to ignore for
loops with trivial or non-existent conditions.
Inspection options
Option | Type | Default |
---|---|---|
Ignore 'infinite' for loops without conditions | Checkbox | true |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023