【c/c++】break和continue

来源:互联网 发布:鞋子 知乎 编辑:程序博客网 时间:2024/06/05 19:01
#include <stdio.h>#include <conio.h>  //getch()/*break已经在switch-case中发挥很大的作用,还可以用于for、while、do while中,用于跳出循环,执行循环后面的语句*/int main(void){int i = 0;char c;while (1){  /*设置循环*/c = '\0';  /*变量赋初值*/while (c != 13 && c != 27){  /*键盘接收字符直到按回车或Esc键*/c = getch();printf("%c\n", c);}if (c == 27){break;          /*判断若按Esc键则退出循环*/}i++;printf("The No. is %d\n", i);}printf("The end");return 0;}/*continue是加速循环,跳过这一次循环,进入下一次循环,而不是说去执行循环后面的语句*///int main(void){//char c='\0';//while (c!= 13){      /*不是回车符则循环*///c = getch();//if (c == 53)//字符53代表数字5//continue; /*若数字5不输出便进行下次循环*///printf("%c\n", c);//}//return 0;//}//int main(void){//int i = 0;//char c;//while (1){  /*设置循环*///c = '\0';  /*变量赋初值*///c = getch();//if (c == 53){//printf("%c\n", c);//}//else{////break语句对if-else的条件语句不起作用;//break;  //在if-else种,break的功效已经体现了啊。//}//}//printf("The end");//return 0;//}

0 0