+ 8
How while loop works with two conditions in c ??
while(a<7,b<17) { a++; b++; } printf("%d %d",a,b); the answer of this challenge is 17,17 don't know how đ€đ€
6 Answers
+ 9
I'd either go for a<7&&b<17 or a<7||b<17. &&: both conditions must be true, ||: it stops as soon as one of the conditions is true
+ 3
The comma operator evaluates the first expression, throws the value away, and then evaluates the second expression.
if (x = 0)
will not execute, but
if (x = 0, x >-1) will.
You only use , when the first expression *does* something (has a side effect).
+ 3
very thanks
+ 2
I think I understand the question now.
If the answer is 17, 17
the loop should be
while((a<7) || (b<17)){
a++;
b++;
}
This means the loop runs as long as either of the conditions are true. Since both are less than statements only the higher number would matter.
Same thing could be accomplished with
while(b<17){
a++;
b++;
}
If && was used instead of || then the output would be 7 7.
+ 1
You could add two if statements to stop a at 7 and b at 17
int main(void){
int a, b = 0;
while((a<7) || (b<17){
if(a < 7){
a++;
}
if(b < 17){
b++;
}
return 0;
}
}
+ 1
While(a<7 || b<17)
//that for "or"
While(a<7 && b<17)
//that for "and"