> i != i is so I don't get the same number twice. and I go 1 + 7 and 3 + 5
It doesn't have a memory of all it's previous values.
If you want that, you need to store them yourself, and then check each one.
In old C++, the declaration of i looks something like this
Code:
int i;
for ( i = 0 ; i < N ; i++ ) {
}
// i still exists here
In new C++, the declaration of i looks something like this
Code:
{
int i;
for ( i = 0 ; i < N ; i++ ) {
}
}
// i DOES NOT exist here
Note the extra braces, hiding the scope of i from later code.
Solutions
- declare i outside the for loop
- declare another variable which can carry the value of i you want out of the loop.