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;
}
相关推荐
用户298698530142 小时前
Word 文档字符级格式化:Java 实现方案详解
java·后端
复杂网络2 小时前
论最小 Agent 计算机的形态
算法
笨鸟飞不快2 小时前
从单个服务到集群:一次完整的性能排查复盘
java·前端
荣码3 小时前
用Streamlit给AI应用套个界面,10行代码出Web页面
java·python
SamDeepThinking3 小时前
Java微服务练习方式
java·后端·微服务
朦胧之13 小时前
AI 编程-老项目改造篇
java·前端·后端
kisshyshy18 小时前
🍦 雪糕、食堂、火车厢:三幅漫画吃透栈、队列与链表
javascript·算法
程序猿大帅18 小时前
别再只当调包侠了:用 Spring AI 落地 Function Calling,我被大模型硬生生砸出了三个大坑
java
程序员晓琪19 小时前
约定大于配置:基于 Java 包名自动生成 API 版本路由的最佳实践
java·spring boot·后端
Flittly19 小时前
【AgentScope Java新手村系列】(11)中断与恢复
java·spring boot·spring