put if statement inside of loop