what does comma in the while loop do? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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);

4th Jan 2019, 5:59 PM
Vijaya Mishra
Vijaya Mishra - avatar
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
5th Jan 2019, 2:38 AM
Ganesh Moota
Ganesh Moota - avatar
+ 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.
4th Jan 2019, 6:13 PM
Netto po
+ 3
Thank you Netto po, Ganesh, Chilly_Vanilly for the help! :-)
5th Jan 2019, 11:10 AM
Vijaya Mishra
Vijaya Mishra - avatar
+ 3
5th Jan 2019, 11:38 AM
Vijaya Mishra
Vijaya Mishra - avatar
+ 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/
5th Jan 2019, 11:36 AM
shreyash joshi
shreyash joshi - avatar
+ 1
Ur's welcome!
5th Jan 2019, 11:50 AM
shreyash joshi
shreyash joshi - avatar