To illustrate how the cases can be different: Suppose you have an array, and you are looking to find a certain element in it. You might write code like this:
#include <stdio.h>
int array[10] = {12, 34, 56, 77, 89, 123, 456, 789, 1001, 2002};
int main()
{
int i;
for(i = 0; i < 10; i++) {
if(array[i] == 77)
break;
}
if(i < 10)
printf("found it at index %d\n", i);
else
printf("not found\n");
}
But if you got rid of the int i; line and changed it to
for(int i = 0; i < 10; i++) {
you'd get an error, because now i is not defined outside the loop. My compiler prints error: use of undeclared identifier 'i' for the if(i >= 10) line.
The code as I've written it is, arguably, mildly poor style, anyway. It's true that, if you decare i outside the loop, it's available after the loop, and you can use it to know where you found the element you were searching for. But to detect whether you found it or not, you have to repeat the i < 10 test, which is awkward. Another way is to use a separate variable to keep track of where and if you found it:
int main()
{
int found = -1;
for(int i = 0; i < 10; i++) {
if(array[i] == 77) {
found = i;
break;
}
}
if(found >= 0)
printf("found it at index %d\n", found);
else
printf("not found\n");
}
Now you're not trying to use i outside the loop, so there's no problem.