Quick question about a loop.

Shouldn't this be a loop that never ends? It does after about 10 seconds of the program running.

1
2
3
4
5
for(int i = 0; i < i+1; i++)
	{


	}


edit:
This one is a never ending loop though!
1
2
3
4
5
for(int i = 0; i != i+1; i++)
	{


	}
Last edited on
i've tried your code and it is an infinite loop for me
For the first piece of code? Huh, that's odd.
@kong288 - Try it this way:
1
2
3
4
5
6
7
8
9
10
#include <iostream>

using std::cout;
using std::endl;

int main(){
int i = 0;
for(; i < i+1; ++i) { }
cout << i << "\t" << i+1 << endl;
}


Read about integer overflow here: http://www.cplusplus.com/articles/DE18T05o/
Topic archived. No new replies allowed.