To make the code and its output more clear rewrite the program the following way
#include <stdio.h>
int main(void)
{
for ( int i = 1, j = 1; j != 0; )
{
j = i++ <= 5;
printf("%d %d\n", i, j );
}
return 0;
}
The program output is
2 1
3 1
4 1
5 1
6 1
7 0
As the variable j
is calculated as a result of this condtion
i++ <= 5
then it will be always equal to 1
except when i
will be equal to 6
because for this value of i
the condition is evaluted to false that is to 0
and this value is assigned to j
.
So the last iteration of the loop is when i
is equal to 6. In this case after this statement
j = i++ <= 5;
i will be equal to 7
and j will be equal to 0
. These values are outputted in the last iteration of the loop.
7 0