Back to all rules
What this rule checks
A for loop uses its counter variable inside the loop body (e.g. print(i))
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++) { ellipse(i * 20, 50, 5, 5); }
}
FAIL — this code triggers the rule
void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  for (int i = 0; i < 10; i++) { ellipse(random(400), 50, 5, 5); }
}
Overview
Category Topic Iteration
Level Intermediate
Type Custom Zita
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
Java class nl.utwente.processing.pmd.rules.HasLoopCounterUseRule
Message template No for loop uses its counter variable inside the loop body.