why, is this weird behaviour of c++?
Difference between en1 and en2, changed 2 character(s)

#include <iostream>↵
using namespace std;↵
int main()↵
{↵
    string s = "abcd";↵
    int i = -1;↵
    while(i < s.size()){↵
        cout << "inside ";↵
        i++;↵
    }↵
    cout << "outside";↵
    return 0;↵
}↵

why this loop does not run, where as when we initialize i = 0, then it runs properly

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English rashid_aziz 2022-08-02 19:45:38 2 Tiny change: '#include <' -> '\n#include <'
en1 English rashid_aziz 2022-08-02 19:45:07 338 Initial revision (published)