It's not a bug (assuming that the inner loop really should use a new loop variable). The inner for loop uses a new instance of variable i. Check the output of the following small program:
#include <iostream>
using namespace std;
int main(int , char**)
{
for (int i=0; i < 5; i++)
{
cout << i << " ";
for(int i=0; i < 3; i++)
if(i == 0)
cout << i << endl;
else
cout << " " << i << endl;
}
}
#include <iostream>
using namespace std;
int main(int , char**)
{
for (int i=0; i < 5; i++)
{
cout << i << " ";
for(int i=0; i < 3; i++)
if(i == 0)
cout << i << endl;
else
cout << " " << i << endl;
}
}
To copy to clipboard, switch view to plain text mode
But I would also prefer a new name for the inner for loop variable just for code readability.
Bookmarks