flush stdout after each iteration