function in for loop