测试代码与结果:
root@ubuntu:~/testC/testfor# ./for
i is 0,j is 0
i is 1,j is 1
i is 2,j is 2
i is 3,j is 3
i is 4,j is 4
root@ubuntu:~/testC/testfor# cat for.c
#include<stdio.h>
int main()
{
int i=9;
int j=9;
for(i=0,j=0;i<3,j<5;i++,j++)
{
printf("i is %d,j is %d\n",i,j);
}
return 0;
}
由结果与代码可以看出,for循环中间部分的如果是用逗号隔开的两部分,那么其左边(i<3)是不起作用的,编译时可能会有警告(“left-hand operand of comma has no effect”)