int lim1, lim2, nr1, nr2;
lim1=1; lim2=1;
nr1=6; nr2=7;
while (nr1 != lim1 && nr2 != lim2)
{
nr1--; nr2--;
cout << nr1 << ' ' << nr2 << endl;
}
Why does the while stop when nr1
gets to be 1, but nr2
doesn't. Isn't &&
supposed to mean that both conditions have to be met? nr2
isn't 1 at the end of the loop so why doesn't it become an infinite loop?
And why is this loop working? It is an infinite loop, as expected.
while (!(nr1 == lim1 && nr2 == lim2))
{
nr1--; nr2--;
cout << nr1 << ' ' << nr2 << endl;
}
Aren't both conditions checking the same thing?