I have this code:
It is supposed to stop typing when i<0 OR j<0, but it doesn'tCode:#include <stdio.h>
int main()
{
int x, y, i=3, j=4;
for( x=i, y=j; x>=0 || y >=0; x--, y-- )
printf( "%d %d\n", x, y );
return 0;
}
Why?
Printable View
I have this code:
It is supposed to stop typing when i<0 OR j<0, but it doesn'tCode:#include <stdio.h>
int main()
{
int x, y, i=3, j=4;
for( x=i, y=j; x>=0 || y >=0; x--, y-- )
printf( "%d %d\n", x, y );
return 0;
}
Why?
>>x>=0 || y >=0
Should be:
x >= 0 && y >= 0
Ok, thanks pal!
But i don't undertand why. With || when x==-1 it should stop...
Why &&?
test out the logic:
x && y is only true when both x and y are true.
x || y is only false when both x and y are false.
so in your case, the first time x is < 0, y is not, and so your statement evaluates to: True || False which still equals True.