while loops not working?

anyone see whats wrong? It just displays hey there sean 100000000000 of times XD

Now i removed the ; on my while its an infinite loop?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <cmath>
#include <string>
using namespace std

int main()
{
	int x =1;
	while (x <= 10);
	{
		cout << "Hey there sean" << endl;
		x =+1;
	}

	return 0;
}
Last edited on
In the loop you set x to 1 so it will always stay below 10.
I found out why i had to do x = x+1 not x =+1
As Peter87 says:

x =+1;

This is actually: x = +1;, which is the same as x = 1;

If you want to increment x you want this:

1
2
3
4
5
x += 1;

// or

++x;
Topic archived. No new replies allowed.