zoukankan      html  css  js  c++  java
  • C语言 while

    C语言 while

    while 语句

    流程图

    案例

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    
    int main(void)
    {
        // 格式:while (表达式){}
        // 循环:每次循环将变量i加1直到10停止
        int i = 0;
        while (i < 10)
        {
            printf("%d
    ", i);
            i++;
        }
        return 0;
    }
    while 使用案例
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    
    // 敲7程序
    int main(void)
    {
        int i = 1;
        while (i <= 100)
        {
            if (i % 7 == 0 || i % 10 == 7 || i / 10 == 7)
            {
                printf("敲桌子
    ", i);
            }
            else
            {
                printf("%d
    ", i);
            }
            i++;
        }
        return 0;
    }
    while 使用案例:敲七

    do…while 语句

    流程图

    dowhile 与 while 区别

    int i = 0;
    
    // dowhile会先执行语句在判断表达式
        do 
        {
            printf("%d
    ", i);
            i++;
        } while (i < 10);
    
    
    // while会先判断表达式在执行语句
        while (i)
        {
            printf("%d
    ", i);
            i++;
        }

    案例

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    
    int main(void)
    {
        int i = 0;
    
        // do{} while (表达式);
        // 限制性语句、在判断表达式
        do 
        {
            printf("%d
    ", i);
            i++;
        } while (i < 10);
    
        return 0;
    }
    while..do 使用案例
  • 相关阅读:
    感想
    正则表达式
    推送、透传、MQ
    Spring集成Quartz定时任务 ---- 定时执行
    代码优化
    nginx配置详解、端口重定向和504
    JAVA实现EXCEL导出
    js 按需加载
    MyBatis使用(二)分页查询
    MyBatis使用(一)
  • 原文地址:https://www.cnblogs.com/xiangsikai/p/12373177.html
Copyright © 2011-2022 走看看