int i vs int index等。哪一个更好? [英] int i vs int index etc. Which one is better?

查看:181
本文介绍了int i vs int index等。哪一个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能的重复项:

是一个名为i的变量不可接受吗?

什么是循环变量的理想变量命名约定?

我一直使用 int i 用于通用循环变量。当然,在大的嵌套循环或其他复杂的东西,我可以使用一个描述性的名字,但你最喜欢看哪一个。

Coming from a C background I've always used int i for generic loop variables. Of course in big nested loops or other complex things I may use a descriptive name but which one had you rather see?

int i;
for(i=0;i<Controls.Count;i++){
  DoStuff(Controls[i]);
}

int index;
for(index=0;index<Controls.Count;index++){
  DoStuff(Controls[index]);
}

在当前项目中,我正在处理这两种样式和索引由 ndx 替换。

In the current project I am working on there are both of these styles and index being replaced by ndx.

哪一个更好? i 变量太泛吗?还有其他C风格名称? i,j,k 是否所有这些都被实际的描述性变量取代?

Which one is better? Is the i variable too generic? Also what about the other C style names? i, j, k Should all of these be replaced by actual descriptive variables?

推荐答案

i 在第一个循环中是非常标准的,其次是 j

i, however, is pretty standard in terms of the first loop, followed by j for an inner loop and k for an inner-inner loop, and so on.

与几乎所有的命名规则一样,对于内部循环, k 只要它是一个项目的标准,并为所有成员工作良好,那么很好。

As with almost all naming rules, as long as it is standard within a project, and works well for all members thereof, then it's fine.

这篇关于int i vs int index等。哪一个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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