0
Why we use variable (i) in loops not any variable ?
2 Réponses
+ 1
Hi,
I guess it is a sort of convention that stands for the "i" of "i"ndex or "i"teration but you can use whatever you want of course
0
When working with vectors in mathematics, you will be familiar with unit vectors. There is a unit vector for each axis of the system. On the x axis the vector is symbolised with 'i' while on the y, with 'j'. Since for loops can be used very often to display arrays, if the array is 1-dimentional for example.
[1,2,3,4,5,6,7,8,9,0]
(It has only one dimention so we call it x), you will need only one for loop to display it. While if it is a 2 dimentional array:
[ [0,1,2],
[3,4,5],
[6,7,8] ]
you are going to need 2 for loops to display it. the external one for the y axis(j variable) and the nested one for the x axis(i variable). I guess that'e where it comes from