+ 3

For loops

I know this question is kinda strange, but why are the variables in for loops often named “i”? It would make much more sense to name them “a” and go in alphabetical order if you have a for loop inside another one.

28th Dec 2017, 4:57 AM
Jacob Pembleton
Jacob Pembleton - avatar
6 Respostas
+ 7
I would agree with Jamie. "i" is used as an indexer in sequences in math. It is likely carried over to programming for that reason as loops are effectively creating a sequence.
28th Dec 2017, 5:06 AM
Mark McGhee
Mark McGhee - avatar
+ 7
"I" isn't compulsory.Its just something programmers have gotten addicted to.You can use other variables as iterators if you want
28th Dec 2017, 6:02 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 5
It's just used for convinence I think. As we say x,y,z axis not a,b,c axis. In series and sequence we let 'nth' term not 'ath' term. While removing proportionality we let 'k' to be proportionality constant, not a. We let angles as 'theta' and 'phi' not a,b. We let polar co-ordinate as (r,theta,phi) not (a,b,c). The reasons are same. Other coders are saying that "iterator" was the reason to choose this convention.
28th Dec 2017, 8:01 AM
Qwqwq Rt
Qwqwq Rt - avatar
28th Dec 2017, 6:49 AM
Taabeer Murtaza
Taabeer Murtaza - avatar
+ 2
I = iterator often replaced with "iter" tho iter should be reserved for vectors and the like when using actual iteration types.
28th Dec 2017, 6:33 AM
Michael Simnitt
Michael Simnitt - avatar
- 1
maybe because usually they are used as indexes for array.
28th Dec 2017, 8:58 AM
shobhit
shobhit - avatar