关于continue的用法疑问:

关于continue的用法疑问:

题目
关于continue的用法疑问:
// animal.c
#include
#include
int main(void)
{
char ch;
printf(" Give me a letter of the alphabet,and i will give ");
printf(" an animal name \n beginning with that letter.\n");
printf("Please type in a letter :type # to end my act.\n");
while((ch= getchar()) = '#');
{
if('\n'==ch)
continue;
if(islower(ch))
switch(ch)
{
case 'a':
printf("argali,awild sheep of Asia\n");
break;
case 'b':
printf("bablirusa,a wild pig of Malay \n");
break;
case 'c':
printf("coati,racoonlike mammal \n");
break;
case 'd':
printf("Desman,aquatic,molelike critter \n");
break;
case 'e':
printf("echidna,the spiny anteater\n");
break;
case'f':
printf("fisher,brownish marten \n");
break;
default:
printf("That's a stumper \n");
}
else
printf("I recognize only lowercase letters.\n");
while(getchar()!='\n')
continue;
printf("Please enter another letter of a #.\n");
}
printf("Bye!\n");
return 0;
}
编译了一下,发现有问题:
错误提示是:
--------------------Configuration:animal2 - Win32 Debug--------------------
Compiling...
animal2.c
D:\我的文档\animal2.c(13) :error C2044:illegal continue
Error executing cl.exe.
animal2.obj - 1 error(s),0 warning(s)
答案
你的while后面有个分号.后面那个大括号就不在while里了,所以continue也不再while里,continue只有在循环内才有意义,否则就会出现这种错误.
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点

超级试练试题库

© 2017-2019 超级试练试题库,All Rights Reserved.