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?
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
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
Ok, thanks pal!
But i don't undertand why. With || when x==-1 it should stop...
Why &&?
Loading.....
( Trying to be a good C Programmer )
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.