As far as variable naming conventions go, should iterators be named i
or something more semantic like count
? If you don't use i
, why not? If you feel that i
is acceptable, are there cases of iteration where it shouldn't be used?
相关问题
- Batch - Set variables in for loop
- JavaScript, confusing syntax when declaring a vari
- Efficiently chunk large vector into a vector of ve
- How can I create a new variable based on condition
- Why is a variable not updating after changing its
相关文章
- How can I unpack (destructure) elements from a vec
- Python relative import with more than two dots
- Insert into vector with conditional iterator
- Loss of variables switching orientations
- Bind a char to an enum type
- What is the limit in size of a Php variable when s
- Should I keep bad naming conventions?
- Makefile and use of $$
If the "something more semantic" is "iterator" then there is no reason not to use i; it is a well understood idiom.
my feeling is that the concept of using a single letter is fine for "simple" loops, however, i learned to use double-letters a long time ago and it has worked out great.
i asked a similar question last week and the following is part of my own answer:
in case the benefit isn't immediately obvious: searching through code for any single letter will find many things that aren't what you're looking for. the letteri
occurs quite often in code where it isn't the variable you're looking for.i've been doing it this way for at least 10 years.
note that plenty of people commented that either/both of the above are "ugly"...
I should point out that i and j are also mathematical notation for matrix indices. And usually, you're looping over an array. So it makes sense.