AFAIK the code between parens in the foreach statement is executed just once to obtain a list over which to iterate. So yours is not really an optimization. Update: i see now your and suaveant point as the inner loop get called multiple times: the original post was not that clear.
Very true... but the inner foreach loop gets called multiple times... so there would be a bit of savings... certainly good advice in this case... in a single for loop it would make no difference.