Ad if condition to inner loop