I am trying to run a loop on vector but not on the last two elements. So for that I used the following implementation:
vector<int> x;
for(int i=0;i<x.size()-2;i++){
cout<<"looping over element"<<endl;
}
However, running the above code with no elements inserted into x leads to an infinite loop. Ideone link:
Why do I get this behavior? If x.size()==0
then i<-2
condition should not hold and the code should never enter the for loop