Is it bad to identify an integer's value and then re-identify it in a for loop? I always fear unidentified variables and I dint know whether this will cause me problems once I get better. Examples:
1 2 3 4 5 6
int i = 109;
for (int i = 0; i < 99; i++) //Made i equal to 0 after assigning it 89
{
cout << i << "\n";
}
Example #2:
1 2 3 4 5 6
int i = 543;
for (int i = 0; i < 100; i++); //made i a different value, and it is lower than the condition in the for statement.
{
cout << i << "\n";
}
Will the for loop in example 2 even start? (I would assume it does because i is reinitialized to 0.)
Is this ok in do-while loops and while loops as well?
The i defined on line 1 is a completly different variable from the i defined on line 3. The i that is being used on line 5 is the i that was defined on line 3. It is better to use different variable names to avoid confusion.