for循环的缺点 [英] Disadvantage of for loop

查看:205
本文介绍了for循环的缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for循环的实际缺点是什么?不,我的意思很重。必须有正确的东西。有while和do while循环,都有效,但我们有一个for循环。在for循环中必须有一些缺点,因为while和do while都是开发的,是吗?

What are the actual disadvantages of for loop? No, I mean seriously. There must be something right. There are while and do while loops, both effective, yet we have a for loop. There must be some disadvantage in for loop due to which while and do while were developed, right?

推荐答案

否, while loops是循环的基本结构,基于条件goto或汇编跳转,如果你愿意的话。但是,因为下面的代码被写入所有的时间去通过数组:

No, while loops are the basic structure for making loops, based on conditional gotos or assembly jumps if you will. However, because the following code was being written all the time to go through arrays:

int i = 0;
while (i < N)
{
    //do something, probably access an array
    i++;
}

他们创建了一个更干净,更可读的方法:

They created a cleaner, more readable, way to do this:

for(int i = 0; i < N; i++)
{
    //do something
}

这是一个名为语法糖

因为没有对于这些类存在的东西,一个着名的报价,Alan Perlis走语法糖造成分号的癌症。

Because there is no inherent reason for these kind of things to exist a famous quote of Alan Perlis goes "syntactic sugar causes cancer of the semicolon".

话虽如此,你总是要努力获得更多可读的代码,所以去吧。

That being said, you always have to strive for more readable codes, so go for it.

这篇关于for循环的缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆