for语句问题
来源:百度知道 编辑:UC知道 时间:2024/05/16 07:05:44
for(j=1;j<=8;j++)
if((i+j)%2==0)
printf("%c%c",219,219);
else
printf(" ");
printf("\n");
和
for(j=1;j<=8;j++)
{
if((i+j)%2==0)
printf("%c%c",219,219);
else
printf(" ");
printf("\n");
}
有什么区别啊,翻书没有查到
if((i+j)%2==0)
printf("%c%c",219,219);
else
printf(" ");
printf("\n");
和
for(j=1;j<=8;j++)
{
if((i+j)%2==0)
printf("%c%c",219,219);
else
printf(" ");
printf("\n");
}
有什么区别啊,翻书没有查到
第一个程序,最后的printf("\n"); 不在for循环的循环体中,因此,它在for循环结束之后才会执行一次。
第二个程序,最后的printf("\n"); 在for循环的循环体中,因此,它会在每次执行循环体时执行一次,所以共要执行8次。
有区别
for(j=1;j<=8;j++)
if((i+j)%2==0)
printf("%c%c",219,219);
else
printf(" ");
printf("\n"); <-这句不在for循环里面
for(j=1;j<=8;j++)
{
if((i+j)%2==0)
printf("%c%c",219,219);
else
printf(" ");
printf("\n"); <-这个在for里面
}
区别是少了2个中括号
上面那个格式不正确
无法编译通过