place if block inside loop