初学循环语句

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值