+ 8

In the code below, what does "i" mean and is it compulsory to use it?

for (i=1; i<=5; i++) { document.write(i + "<br />"); }

5th Jul 2017, 6:07 AM
Kabulput
Kabulput - avatar
4 Antworten
+ 10
it's use for iteration. though you can you use any letters you like but it would be easier to recall "i" for iteration. 😊
5th Jul 2017, 6:18 AM
CC Calvello
CC Calvello - avatar
+ 6
'i' is the iterator of the for-loop. It has an initial value of '1'. This value will be increased by '1' every time the loop is running trough and til the condition (i<=5) is true.
5th Jul 2017, 6:28 AM
Dennis Brem
Dennis Brem - avatar
+ 5
btw be carefull If you use nested loops and make sure that you usw different variables for each loop
5th Jul 2017, 8:37 AM
Dennis Brem
Dennis Brem - avatar
+ 2
"i" is variable name defined by FOR loop. You can use any other name for this variable.
5th Jul 2017, 6:14 AM
A l
A l - avatar