Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java- Why for uses i,j [duplicate]

Tags:

java

for-loop

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 ?

like image 625
Arpssss Avatar asked Nov 28 '22 14:11

Arpssss


1 Answers

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.

like image 181
NPE Avatar answered Dec 16 '22 01:12

NPE