Assignment to 'for' loop parameter
Reports assignment to, or modification of a for
loop parameter inside the body of the loop.
Although occasionally intended, this construct may be confusing and is often the result of a typo or a wrong variable being used.
The quick-fix adds a declaration of a new variable.
Example:
After the quick-fix is applied:
Assignments in basic for
loops without an update statement are not reported. In such cases the assignment is probably intended and can't be easily moved to the update part of the for
loop.
Example:
Use the Check enhanced 'for' loop parameters option to specify whether modifications of enhanced for
loop parameters should be also reported.
Inspection options
Option | Type | Default |
---|---|---|
Check enhanced 'for' loop parameters | Checkbox | true |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |