Back to all rules
What this rule checks
For-loop declares only one control variable
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++) {
    float x = i * 40;
    ellipse(x, 200, 30, 30);
  }
}
FAIL — this code triggers the rule
void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  for (int i = 0, x = 0; i < 10; i++, x += 40) {  // two loop variables
    ellipse(x, 200, 30, 30);
  }
}
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/ForLoopVariableCount
Properties
maximumVariables = 1