Problem with while loops

I'm having some trouble with a few while loops. I've written them, and they worked great originally, however I added code to a different part of my program, and now the loop runs infinitely.

Heres my code for the while loops:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
while(inventory[x].invno!="")
	{
		while(inventory[x].miscitems!="")
		{
			cout << inventory[x].invno << " " << inventory[x].miscitems << " " << inventory[x].invamt << endl;
			x++;
		}
		x = 0;
		while(inventory[x].weapon!="")
		{
			cout << inventory[x].invno << " " << inventory[x].weapon << " " << inventory[x].invamt << endl;
			x++;
		}
		x = 0;
		while(inventory[x].armor!="")
		{
			cout << inventory[x].invno << " " << inventory[x].armor << " " << inventory[x].invamt << endl;
			x++;
		}
	}


And I just added this to my code:
1
2
3
4
5
6
7
8
std::stringstream strm;
std::string num;
int u = 0;
u = j;
j += 1;
strm << j;
strm >> num;
inventory[u].invno = num;


When the loop actually worked, I had that part just written as
inventory[j].invno = j;
However, in the loops, the inventory[x].invno would not display. Now, I can tell it displays, but the code loops infinitely.
Any ideas why?
You are checking conditions that never will be changed within your loop. Unless some element in inventory doesn't have an empty string, and then gets checked by x, your loops will repeat infinitely.
Oh! Wow! How did I miss that? Thanks very much!
No problem.
Topic archived. No new replies allowed.