A little trouble with for loop


why this working

for (var i=1;i<10;i+=1){
console.log("I love coding!");


for (var i=1;i=10;i+=1){
console.log("I love coding!");

this is wrong?


Hi, here

for (var i=1;i=10;i+=1)

this part


you are storing 10 to the variable i and in the first code

i <10

you ptu the condition of the loop as long as i is less than 10


You mean if I set an exact value to the second i then the loop wouldn't start, which means i would not add 1 automatically until it gets to 10?
So only comparison is accepted in for loop?


So only comparison is accepted in for loop?
There are three parts in the for loop

for(statement1, statement2, statement3) {
    #do something

the statement1 is where you declare the variable, the statement2 is where you put the condition then the statement3 is where you increase the variable.


Ok, I see. Thank you!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.