Hey -
I thought I knew the answer to this, but I just got a weird error trying to do this, so...
Observe the following code:
for (int n = 1; n <= 100; n++)
{
//Do stuff
}
//Do more stuff
for (int n = 1; n <= 100; n++) //Yes, they have to be separate loops
{
// Do another loop
}
------
Now, I thought scope is limited within a for loop... meaning that once the first for loop terminates, n is out of scope/doesn't exist. Ergo, I would need to create it again. I was CERTAIN that's what happened, and yet when I tried to compile the above code with MS VC++6 SP4, I got a compiler error on the second for loop, saying that n was already initialized.
Is this is just a compiler optimization bug, or am I off on the scope issue?
Thanks,
Andrew
I thought I knew the answer to this, but I just got a weird error trying to do this, so...
Observe the following code:
for (int n = 1; n <= 100; n++)
{
//Do stuff
}
//Do more stuff
for (int n = 1; n <= 100; n++) //Yes, they have to be separate loops
{
// Do another loop
}
------
Now, I thought scope is limited within a for loop... meaning that once the first for loop terminates, n is out of scope/doesn't exist. Ergo, I would need to create it again. I was CERTAIN that's what happened, and yet when I tried to compile the above code with MS VC++6 SP4, I got a compiler error on the second for loop, saying that n was already initialized.
Is this is just a compiler optimization bug, or am I off on the scope issue?
Thanks,
Andrew