+ 9
what does comma in the while loop do?
int a=0,b=0; while(a<7,b<17) { a++; b++; } printf("%d,%d\n",a,b);
6 Respostas
+ 7
When there are multiple conditions in a while loop separated by comma (, , ,) then these conditions are evaluated from left to right in order but the truth value of the condition present to the extreme right decides the termination condition of while loop
ex 1:
#include<stdio.h>
int main()
{
int a=0,b=0;
while(a<7,b<17)
{
a++;
b++;
}
printf("%d %d",a,b);
return 0;
}
output:17 17
+ 5
The comma operator, in that case, evaluates the two statements, but only verify the true-ness of the first argument. Let's suppose that we have the below While structure:
while(i++, i <= 10);
It will add one to var I and verify if i <= 10 equals true, if so, it will do the loop-block, if false, it won't do.
+ 3
+ 3
Thanks shreyash joshi
+ 2
Refer this link to know in detail about the comma operator:
https://www.google.com/amp/s/www.geeksforgeeks.org/a-comma-operator-question/amp/
+ 1
Ur's welcome!