#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
初识循环语句--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;
}