复习的时候遇到的问题
while()
{if()
continue;
语句;
}
问题一:continue不是只能在循环语句里么?上面难道不是在if语句中?
还有continue跳过本次循环,跳过的为什么不是if语句?书上说continue应该跳出嵌套在里面的循环而跳到外面
//////////////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <conio.h>
int main(void)
{float length,width;
printf("Enter the length of the rectangle:\n");
while(scanf("%f",&length)==1)
{
printf("Length=%0.2f:\n",length);
printf("Enter its width:\n");
if(scanf("%f",&width)!=1) //问题二:在上一语句printf以后,不管输入是否正确都要执行if中的条件判断??
break;
printf("Width=%0.2f:\n",width);
printf("Area=%0.2f:\n",length*width);
printf("Enter the length of the rectangle:\n");
}
printf("Done.\n");
getch();
return 0;
}
/////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
int main(void)
{char ch;
printf("111111111111.\n");
while((ch=getchar())!='#')
{if('\n'==ch)
continue;
if(islower(ch))
switch(ch)
{
case 'a':
printf("argali,a wild sheep of Asia\n");
break;
default:
printf("That's a stumper!\n");
}
else
printf("nnnnnnnnnnnnn.\n");
while(getchar()!='\n') //问题三:这里的while作用我实在不明白,去掉我执行了,没变化
continue;
printf("2222222222222.\n");
}
printf("BYE!\n");
getch();
return 0;
}
[解决办法]
while(getchar()!='\n') //问题三:这里的while作用我实在不明白,去掉我执行了,没变化
continue;
-------------------------
知道输入是换行才会结束循环
[解决办法]