Infinite Loop problem

This is a discussion on Infinite Loop problem within the C++ Programming forums, part of the General Programming Boards category; The following segment of code is part of a program to calculate the NZVC bits when adding two binary numbers ...

1. Infinite Loop problem

The following segment of code is part of a program to calculate the NZVC bits when adding two binary numbers together. This particular segment will determine the Z bit (whether or not the entire binary number equals zero).

However, it is an infinite loop and I can't figure out why. I've already nailed down the problem to somewhere in this segment of code, as everything else worked perfectly when I commented it out.

For those wondering, the extra space of b3 (b3[0]) in a 9-space array, contains the Carry-Out (C) bit.

Code:
```        z = 1;
i = 8;
while (z != '0')
{
while (i>0)
{
if (b3[i] == '1')
z = 0;
else
i--;
}
}
cout << "The Zero bit is " << z << endl;```

2. The char '0' is not the same value as the number 0 so your first loop will never end.

Jim

3. How do I store the integer 0 there instead? I removed the 's, but same result. Infinite loop.

4. What? You're already storing the integer into z. But you're trying to compare the character '0' to this int. The char '0' has an int value of 48. You probably want to compare z to 0 the integer not the character '0'.

Jim

5. Even though the char 0 has the ASCII value of 48 (this is implementation defined by the way -- the character constant 'a' might not be 48) don't use 48, use the char constant '0' (i.e. with the single quotes around the 0)