您的位置:首页 > 其它

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

2017-02-20 21:59 369 查看
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();

        }

优点:循环的效率高

缺点:程序不简洁
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐