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;