Vinayaka2000's blog

By Vinayaka2000, history, 2 years ago, In English

Hello codeforces, I'm trying to execute the below piece of code but for some reason, it's getting into an infinite loop and causing a TLE. Please let me know why this is exactly happening ?

#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> v;
    for(int i=0; i<v.size()-1; ++i) {
        cout << " inside " << endl;
    }
}

Ideally, the size of the vector should be zero and in the for loop, 0<(0-1) must be false and the for loop must not execute. When I use the below code, its not executing the for loop. I'm sure it's not because of precedence of < over -.

#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> v;
    for(int i=0; i<0-1; ++i) {
        cout << " inside " << endl;
    }
}

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it