C语言-while循环,continue/break,getchar()/putchar()

while循环中的continue/break

复制代码
#include<stdio.h>

int main() {

	//while循环中 continue  和 break 的不同
	//break是用于永久的终止循环
	//continue 跳过本次循环后面的代码,直接去判断部分,进行下一次的循环的判断

	int i = 1;
	//while (i <= 10) {
	//	if (i == 5)
	//		break;
	//	printf("%d ", i);
	//	i++;
	//}
	//while (i <= 10) {
	//	if (i == 5)
	//		continue;
	//	printf("%d ", i);
	//	i++;
	//}
	while (i <= 10) {
		i++;
		if (i == 5)
			continue;
		printf("%d ", i);
	}
	return 0;
}

getchar()/putchar()

复制代码
#include<stdio.h>
int main() {
	////EOF ;//end of file
	//int ch=getchar();//输入获得一个字符
	////下面的两种打印方式相同
	//printf("%c\n", ch);//1
	//putchar(ch);//2

	//int ch = 0;
	//while ((ch=getchar())!=EOF) {
	//	putchar(ch);
	//}

	//举一个应用例子
	//假设密码是一个字符串
	//char password[20] = { 0 };
	//printf("请输入密码:>");
	//scanf("%s", password);
	////
	////getchar();//读走了\n

	//int ch = 0;
	//while ((ch=getchar())!='\n') {
	//	;
	//}

	//printf("请确认密码(Y/N):>");
	//int ret = getchar();
	//if ('Y'==ret)
	//{
	//	printf("Yes\n");
	//}
	//else {
	//	printf("No\n");

	//}

	char ch = '\0';
	while ((ch = getchar()) != EOF) {
		if (ch<'0'||ch>'9')
			continue;
			putchar(ch);//只打印数字字符,跳过其他字符

	}
	return 0;
}
相关推荐
lueluelue4721 小时前
LeetCode:链表
算法·leetcode·链表
橘子汽水1681 天前
Leetcode 23,543合并K个升序链表,二叉树的直径
算法·leetcode·链表
huameinan狮子1 天前
Adaboost算法原理与计算实例
算法
别怪我很水1 天前
API中提供了VelocityTracker类用于计算触摸事件MotionEvent的速度,而其内部默认使用的方法就是最小二乘法,本 ...
算法·gitee·最小二乘法
都叫我大帅哥1 天前
Java JJWT 完全指南:从入门到生产级实践
java
前端开发张小七1 天前
Java 学习笔记 · 第一课:基础语法与核心概念
java·后端
ThsPool1 天前
【ENVI二次开发学习整理 04】ENVI功能扩展与二次开发
java·前端·javascript
赤壁小虾1 天前
【渲染流水线】[逐片元阶段]-[透明度测试]以UnityURP为例
java·前端·数据库
Re.不晚1 天前
挑战做100道力扣算法- DAY1
算法·leetcode·职场和发展