Depends on the compiler: some are more flexible than others.
For some compilers this is a redefinition because they see the
i
as having a scope limited to the whole main function, rather than just the
for
loop with which it is associated.
However, the most likely reason you are getting it would be to forget the semicolon at the end of the first loop, which would make it:
#include <iostream>
void main()
{
for(int i=0;i<10;i++)
for(int i=0;i<10;i++);
}
Unless you copy'n'pasted your code direct from your source file, I'd have a look for that...
But even if you did, it is a very, very bad practice to use a semicolon at the end of a loop, and if your compiler is not giving you a warning then you need to enable it. If it is giving you a warning, then you need to change it's options to "Treat warnings as errors" - particularly when you are learning.
It's far too easy to write code like this:
#include <iostream>
void main()
{
int i;
for(i=0;i<10;i++);
{
printf(i);
}
}
And spend a long time trying to work out what is wrong with your program.
There are other little traps like that you need to make sure teh compielr won;t let you make:
if (a == b);
c = 0;
And the classic:
if (a = b)
c = 0;
Making your compiler as strict as possible prevents a lot of hair pulling!