Address SonarQube critical: Loop counters should not be assigned to from within the loop body