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;
}
相关推荐
kong79069282 小时前
SpringBoot原理
java·spring boot·后端
say_fall2 小时前
二叉树从入门到实践:堆与链式结构全解析
c语言·数据结构·c++
那我掉的头发算什么2 小时前
【图书管理系统】基于Spring全家桶的图书管理系统(下)
java·数据库·spring boot·后端·spring·mybatis
一条大祥脚2 小时前
KMP原理+例题
算法
大闲在人10 小时前
C、C++区别还是蛮大的
c语言·开发语言·c++
小灵不想卷11 小时前
LangChain4j Low 和 Hight-level API
java·langchain4j
Cosmoshhhyyy11 小时前
《Effective Java》解读第39条:注解优先于命名模式
java·开发语言
亓才孓11 小时前
[SpringIOC]NoSuchBeanDefinitionException
java·spring
追随者永远是胜利者12 小时前
(LeetCode-Hot100)20. 有效的括号
java·算法·leetcode·职场和发展·go