Do not call a function when declaring a for-type loop in order to avoid function calls each iterations. It saves CPU cycles.

Non compliant Code Example

public void foo() {
    for (int i = 0; i < getMyValue(); i++) {  // Noncompliant
        System.out.println(i);
        boolean b = getMyValue() > 6;
    }
}

Compliant Solution

public void foo() {
    int myValue = getMyValue();
    for (int i = 0; i < myValue; i++) {
        System.out.println(i);
        boolean b = getMyValue() > 6;
    }
}

Exceptions

Iterator methods such as next() and hasNext() are allowed. Function calls inside the instanciation of the for loop are allowed.