[C++] Why is this simple piece of code causing TLE ?

Revision en2, by Vinayaka2000, 2022-10-03 17:22:46

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;
    }
}
Tags c++, cpp, error, help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Vinayaka2000 2022-10-03 17:22:46 7
en1 English Vinayaka2000 2022-10-03 17:21:43 856 Initial revision (published)