Back to all rules
What this rule checks
A for loop folds array elements into a variable declared outside the loop (e.g. sum = sum + a[i])
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
int[] xs = {1, 2, 3};
void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  int total = 0;
  for (int i = 0; i < xs.length; i++) { total = total + xs[i]; }
  println(total);
}
FAIL — this code triggers the rule
int[] xs = {1, 2, 3};
void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  for (int i = 0; i < xs.length; i++) { int copy = xs[i]; println(copy); }
}
Overview
Category Topic Arrays
Level Intermediate
Type Custom Zita
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
Java class nl.utwente.processing.pmd.rules.ArrayLoopAggregateRule
Message template No for loop folds array elements into a variable (e.g. sum = sum + a[i]).