public void foo() {
for (int i = 0; i < getMyValue(); i++) { // Noncompliant
System.out.println(i);
boolean b = getMyValue() > 6;
}
}
Do not call a function when declaring a for-type loop in order to avoid function calls each iterations. It saves CPU cycles.
public void foo() {
for (int i = 0; i < getMyValue(); i++) { // Noncompliant
System.out.println(i);
boolean b = getMyValue() > 6;
}
}
public void foo() {
int myValue = getMyValue();
for (int i = 0; i < myValue; i++) {
System.out.println(i);
boolean b = getMyValue() > 6;
}
}
Iterator methods such as next() and hasNext() are allowed. Function calls inside the instanciation of the for loop are allowed.