Possible Duplicate:
Why are we using i as a counter in loops?
Why are variables “i” and “j” used for counters?
This may seems stupid, but why everybody use i (if i is already in use, then j) in for loop checking ?
Means:
for(int i = 1;i <= 5;i++){
for(int j = 1;j <= i;j++){
System.out.print(i);
}
Why i and j ? We can use first and second also ? Check this, all (9 out of 10) uses i, j. Why ? Any reason or just doing because everybody does that ?
This programming convention has been around for a long time, and probably goes back all the way to Fortran. In Fortran 77, variables beginning with the letters I, J, K, L, M, or N were taken to be of type INTEGER
(unless explicitly declared otherwise). That made them very well suited to be loop variables.
Of course i
, j
etc have been used in maths to denote matrix/vector/summation indices for much, much longer than computers have existed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With