std::vector<int> tmp = ...
for(int i = 0; i <= tmp.size() - 3; i+=2){
std::cout << "i: " << i << " , tmp.size(): " << tmp.size() << std::endl;
if(tmp[i] == tmp[i+1]){
final.push_back(tmp[i] * 2);
}else{
final.push_back(tmp[i]);
final.push_back(tmp[i + 1]);
}
std::cout << "\ntmp.size() at the end of loop: " << tmp.size() << "\n";
}
I have the following output:
Why does the loop execute as i
is clearly much much bigger than tmp.size()
?