Back to all rules
What this rule checks
Iterates an array with an index-based for loop
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
float[] heights = new float[8];

void setup() {
  size(400, 400);
  for (int i = 0; i < heights.length; i++) {
    heights[i] = random(50, 300);
  }
}

void draw() {
  rect(20, 0, 40, heights[0]);
}
FAIL — this code triggers the rule
float[] heights = {120, 250, 80};

void setup() {
  size(400, 400);
}

void draw() {
  for (int i = 0; i < 3; i++) {
    rect(20 + i * 50, 0, 40, heights[0]);  // the loop never indexes with i
  }
}
Overview
Category Topic Arrays
Level Intermediate
Type Custom Zita
Priority 1 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
Java class nl.utwente.processing.pmd.rules.ArrayIndexForLoopRule
Message template No index-based for loop found for array iteration.