I am surprised: you think that it is more optimal to do this at each iteration than at the end. Maybe the true motivation is that you want to avoid storing all the permutation results ?