I've been wondering about this. For a variable that is used in a very large loop, is it better to initialize it first with a dummy value on top of the loop (outside) or should it be declared and initialized as locally as possible, at the moment it's used inside the loop?
I'm asking because these two posts related to my question seem to give contradictory answers:
Declare variables at top of function or in separate scopes?
Should we use temporary variables for the returned values of functions?
One says that it should be declared as locally as possible - I'm assuming this means variables should be declared within loops. The other seems to suggest that local declarations in large loops yield poor performance unless some other special technique is used (I'm not familiar with the example provided by the best answer in this case).