#include <stdio.h>
int main() {
//while()
char CH;
int count=0;
while(count < 10){
CH = getchar();
if(CH != ' ')
continue;
putchar(CH);
count++;
}
printf("Hello, World!\n");
return 0;
}
#include <stdio.h>
int main() {
char ch;
int cunt;
int i;
for(cunt=0;cunt<10;cunt++){
ch = getchar();
for(i=0;i<5;i++){
if (ch != ' ')
continue;
putchar(ch);
printf("我是内层循环的---小可爱!!!\n");
}
printf("我是外层循环的---小可爱!!!\n");
printf("如果continue语句在嵌套循环内,则只会影响包含continue的内层循环,不影响外层循环!!!\n");
}
printf("Hello, World!\n");
return 0;
}
continue跳出本次循环,执行下一次循环。
break跳出整个循环
#include <stdio.h>
int main() {
//while()
char CH;
int count=0;
while(count < 10){
CH = getchar();
if(CH != ' ')
break;
putchar(CH);
count++;
}
printf("Hello, World!\n");
return 0;
}
#include <stdio.h>
int main() {
char ch;
int cunt;
int i;
for(cunt=0;cunt<10;cunt++){
ch = getchar();
for(i=0;i<5;i++){
if (ch != ' ')
break;
putchar(ch);
printf("我是内层循环的---小可爱!!!\n");
}
printf("我是外层循环的---小可爱!!!\n");
printf("如果continue语句在嵌套循环内,则只会影响包含continue的内层循环,不影响外层循环!!!\n");
}
printf("Hello, World!\n");
return 0;
}
#include <stdio.h>
int main() {
char ch;
int cunt;
int i;
for(cunt=0;cunt<10;cunt++){
ch = getchar();
for(i=0;i<5;i++){
if (ch != ' ')
break;
putchar(ch);
printf("我是内层循环的---小可爱!!!\n");
}
if (ch != ' ')
break;
printf("我是外层循环的---小可爱!!!\n");
printf("如果continue语句在嵌套循环内,则只会影响包含continue的内层循环,不影响外层循环!!!\n");
}
printf("Hello, World!\n");
return 0;
}
/* animals.c -- uses a switch statement */
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char ch;
printf("Give me a letter of the alphabet, and I will give ");
printf("an animal name\nbeginning 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)) /* lowercase only */
switch (ch)
{
case 'a' :
printf("argali, a wild sheep of Asia\n");
break;
case 'b' :
printf("babirusa, 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");
} /* end of switch */
else
printf("I recognize only lowercase letters.\n");
while (getchar() != '\n')
continue; /* skip rest of input line */
printf("Please type another letter or a #.\n");
} /* while loop end */
printf("Bye!\n");
return 0;
}
遇到break后跳出,继续匹配switch。
顺序执行每个case。