While writing loops I often get confused with which one I should choose. For example,
int sum;
for(int i=0; i<10; i++)
{
sum=0;
...
....
}
Or
for(int i=0; i<10; i++)
{
int sum=0;
...
....
}
Say, the variable is only required in this loop. There is no need of it in the later part of the program. I need the value of the variable sum to be 0 at the beginning of the loop. Which one is the better practice? Re-initializing a variable at the start of the loop or re-declaring it? Which one is more efficient?