MushinZero MushinZero - 1 month ago 17
C++ Question

For loop not incrementing

Sorry but this is a quick question, can anyone tell why this for loop is not incrementing either i or j? They are staying at 0 and 1.

void Environment::tourneyselection(std::vector<Tree>& popvec) {
std:random_shuffle(popvec.begin(), popvec.end());
for (int i = 0, j = 1; j <= Popsize; i + 2, j + 2) {
std::cout << popvec[i].fitness << " and " << popvec[j].fitness << ":";
if (popvec[i].fitness < popvec[j].fitness) {
popvec.erase(popvec.begin() + i);
std::cout << " erase " << i << std::endl;
}
else {
popvec.erase(popvec.begin() + j);
std::cout << " erase " << j << std::endl;
}

}
}


Thank you

Answer
j + 2

You're not modifying j at all. You wanted to say

j += 2

The same thing goes for i + 2.