somebody please explain me why
int i=0,j=10;
while(j>0,i++){
printf("%d%d",i,j);
j--;
}
will not work and
int i=0,j=10;
while(i++,j>0){
printf("%d%d",i,j);
j--;
}
works.
Also please tell me why
int i=0,j=10;
while(j>0,++i){
printf("%d%d",i,j);
j--;
}
gives an infinite loop ?
thanks and regards
harsha
In your while-loop condition you use comma operator, which evaluates its parameters and returns the second one. So in your examples:
while(j>0,i++) - returns i before it gets incremented;
that is 0, so loop won't execute at all
while(i++,j>0) - returns (j > 0) - runs as expected
while(j>0,++i) - returns i - will run until i overflows max int value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With