Code Snippet 1:
int i=1;
for(;;){
if (i<5){
cout<<"Hello World"<<endl;
i++;
}
}
Code Snippet 2:
int i=1;
for(;;){
if (i<5){
cout<<"Hello World"<<endl;
}
i++;
}
Snippet 1 produces an output where "Hello World" is printed 4 times and then the loop continues with no output, which was expected. But, "Hello World" is printed indefinitely in snippet 2. Why does the condition (i<5) not checked in snippet 2 even after i=>5? How does incrementing i (i++) inside or outside the if-block in these snippets making such a difference?