print trace & set errexit for loop function