int i vs int index etc. Which one is better?
Posted
by Earlz
on Stack Overflow
See other posts from Stack Overflow
or by Earlz
Published on 2010-05-21T23:55:58Z
Indexed on
2010/05/22
0:00 UTC
Read the original article
Hit count: 156
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]);
}
or
int index;
for(index=0;index<Controls.Count;index++){
DoStuff(Controls[index]);
}
In the current project I am working on there are both of these styles and index being replaced by ndx
.
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?
© Stack Overflow or respective owner