返回

初识循环语句

发布时间:2022-09-16 06:10:36 316

#define _CRT_SECURE_NO_WARNINGS #include #include ::: hljs-center

## 初识循环语句--while--for

:::


//for(表达式1-初始化,表达式2-判断,表达式3-调整) // 循环语句;


int main() { for (int i = 0;i <= 10;i++) {//i=0判断进入循环->出来i++执行->i=2判断进入循环.... if (i <= 6) continue;//break printf("%d ", i); } return 0; }


/while(表达式--为真执行\为假结束循环) 循环语;/


int main() { int ch = 0; while ((ch = getchar()) != EOF) { if (ch < '0' || ch>'9') continue; putchar(ch); } return 0; }


int main() { int ch = 0; while ((ch = getchar()) != EOF) //EOF--end of file结束文件标志 {//Ctrl+z结束程序 putchar(ch);//==printf("%c",ch); } return 0; }


int main() { int ch = 0; int ret = 0; char password[20] = { 0 }; printf("enter your PIN:>"); scanf("%s", password); while ((ch = getchar()) != '\n'); { ;//将缓冲区多余的字符和\n读走,确保ret等待输入 } printf("please confirm!(Y/N):"); ret = getchar();//ret=getchar()---scanf("%d",ret) if (ret == 'Y') { printf("land successfully!\n"); } else { printf("land failure!"); } return 0; }


int main()//打印1-10 { int i = 0; while (i <= 9) {//>2语句,需用{} if (i == 6) break;//continue; i++;//break结束循环,continue结束本次循环后面 //的代码,进入下一轮循环 printf("%d ", i); } return 0; }

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线
下一篇
动态内存函数 2022-09-16 05:56:59