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:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
AssignmentToForLoopParameter- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Use the Check enhanced 'for' loop parameters option to specify whether modifications of enhanced for loop parameters should be also reported.
Inspection ID: AssignmentToForLoopParameter
Inspection options
Here you can find the description of settings available for the Assignment to 'for' loop parameter inspection, and the reference of their default values.
- Check enhanced 'for' loop parameters
Option ID:
m_checkForeachParametersDefault value:
Selected
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |