zoukankan      html  css  js  c++  java
  • C语言常用知识

    
    

    跳出for循环主要有以下2中方式:

    1、用break语句。如:

    int i;
    for(i=0; i<10; i++)
    {
        if(i>3)    // 如果i>3,跳出for循环,执行printf语句
            break;  
    }
    printf("%d", i);

    2、用return语句(一般用在函数体中,作为函数的返回值跳出该函数,也即跳出了函数体中的for循环)

    int fun(int a)
    {
        int i;
        for(i=0; i<a; i++)
        {
            if(i>3)    // 如果i>3,则函数执行完毕,并返回变量i的值,也即跳出了for循环
                return i;  
        }
    }

    http://www.yalewoo.com/how_to_skip_nested_loop.html

    可以用关键字break来退出for循环。

    具体使用方法可以参考下例:

    int i;
    int a[5]={0,0,0,0,0};
    for(i=0; i<5; i++)
    {
        a[i]=i;
        if(i==3)
            break;  // 当i=3时,退出for循环
    }
    // 以上程序执行完后,数组a的值为0,1,2,0,0

    Loadrunner中的FOR,WHILE,DO 循环语句

    #include "as_web.h"

    int i;

    int whileloop = 1;

    Action()

    {

           //FOR 循环

           for (i=1;i<=10;i++)

                   {

                   lr_output_message( "FOR循环次数: %d", i);

                   }

    // WHILE 循环

           //为了实现上面FOR循环相同效果,这里略复杂点,用到了 && 运算

           i=1;

           while ((i <= 10) && (whileloop ==1))
                   {

                   lr_output_message( "WHILE FOR循环次数:%d", i);

                   i++;

                   }


           //DO WHILE 循环

           //为了实现上面FOR循环相同效果,这里略复杂点,用到了 && 运算
           i=1;

           do {

                           lr_output_message( "DO WHILE 循环次数:%d", i);

                   i++;

                   }
           while (i <= 10) ;

    return 0;
    }

  • 相关阅读:
    node学习报错之883
    vue-cli4创建项目
    Decorator学习笔记
    合天网安实验室学习笔记----Linux基础
    IDF实验室解题学习笔记1
    QA笑话----杂思
    测试优先
    Python的IDE:Eclipse+PyDev配置
    JS实现浏览器的title闪烁
    JSTL实现分页
  • 原文地址:https://www.cnblogs.com/qmfsun/p/4911282.html
Copyright © 2011-2022 走看看