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;
}
相关推荐
码云社区10 小时前
Java租房平台源码方案:Vue 3房源审核、UniApp预约看房与房东管理
java·vue.js
codigger12 小时前
ThreadLocal 会内存泄露吗?
java·内存泄漏·threadlocal
挖掘狂人12 小时前
ThreadLocal 会内存泄露吗?
java·安全·架构
未秃头的程序猿12 小时前
给新模块加了个 @MapperScan,启动崩了,最后发现跟 MapperScan 没关系
java·后端·mybatis
SimonKing13 小时前
WorkBuddy又推出新的限免模型(Hy4 flash)了,羊毛可以薅起来了
java·后端·程序员
Rain的Java大神之路13 小时前
别再死背"三级缓存"了!拿 Spring 7.0.8 源码,把 IoC、AOP、事务、循环依赖四大深水区一次蹚平
java·后端·面试
H H.13 小时前
Java企业级开发:从框架到工程化实战
java·开发语言·经验分享·其他·课程设计
wno70413 小时前
springboot整合FastDFS
java·spring boot·后端
顧棟14 小时前
组件生命周期设计:从硬编码初始化到状态机
java·ide
Pniubi14 小时前
01背包类问题-力扣416.分割等和子集
算法·leetcode·职场和发展