A lot of questions related to for range has been asked around here, but I cannot find the version I need. So, I was reading this book called C Primer 5th edition, and while reading about Vectors I read a line which stated, we cannot use a range for if the body of the loop adds elements to the vector. But just before this line there was a code part written to add elements in the vectors during the run time, i.e.,
vector<int> v2; // empty vector
for (int i = 0; i != 100; ++i)
v2.push_back(i); // append sequential integers to v2
// at end of loop v2 has 100 elements, values 0 . . . 99
All I want to ask is that how can they both contradict to one another? Or are they completely different and not related to one another? If the second one is the condition can you explain me how this works? And if the former is correct can you please explain me why do the code part and the statement contradicted to one another?