Back to all rules
What this rule checks
Loop variables not reassigned in body
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  for (int i = 0; i < 10; i += 2) {
    ellipse(i * 40, 200, 30, 30);
  }
}
FAIL — this code triggers the rule
void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  for (int i = 0; i < 10; i++) {
    ellipse(i * 40, 200, 30, 30);
    i = i + 1;  // changes the loop variable inside the body
  }
}
Overview
Category Topic Iteration
Level Intermediate
Type Built-in PMD
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
PMD reference category/java/bestpractices.xml/AvoidReassigningLoopVariables
Properties
foreachReassign = deny
forReassign = deny