Can anyone help me to understand the way the condition written in the below while()
loop:
Please find the code below:
int fun () {
static int x = 5;
x--;
pritnf("x = %d\n", x);
return x;
}
int main () {
do {
printf("Inside while\n");
} while (1==1, fun());
printf("Main ended\n");
return 0;
}
Output:
Inside while
x = 4
Inside while
x = 3
Inside while
x = 2
Inside while
x = 1
Inside while
x = 0
Main ended
Also I have the below code and the output surprises:
int fun () {
static int x = 5;
x--;
printf("x = %d\n", x);
return x;
}
int main () {
do {
printf("Inside while\n");
} while (fun(),1==1);
printf("Main ended\n");
return 0;
}
Output:
Inside while
x = 4
Inside while
x = 3
Inside while
x = 2
Inside while
x = 1
Inside while
x = 0
Inside while
x = -1
Inside while
x = -2
Inside while
x = -3
.
.
.
.
Inside while
x = -2890
Inside while
x = -2891
Inside while
x = -2892
Inside while
x = -2893
Inside wh
Timeout
In my understanding, the condition is checked from right-to-left. If 1==1 comes on right, the condition is always true and while never breaks.