首页 > 学院 > 开发设计 > 正文

for循环与if判断的嵌套使用

2019-11-08 01:36:42
字体:
来源:转载
供稿:网友
for(i=0; i<N; i++)    {        if(condition)            DoSomething();        else            DoOtherthing();

    }

优点:程序简洁

缺点:多执行了N-1次逻辑判断,并且打断了循环“流水线”作业,使得编译器不能对循环进行优化处理,降低了效率。

if(condition)        {            for(i=0; i<N; i++)                DoSomething();        }        else        {            for(i=0; i<N; i++)                DoOtherthing();        }

优点:循环的效率高

缺点:程序不简洁


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表