3. For or While


#1

Does anyone has an idea why this simple for loop doesn't work?

for(var i=0; i<100; i+20){
console.log(i);
}

it stucks like infinite loop.


#2

that is because it is infinity loop, the problem is in this bit:

i+20

you now tell them: check if i + 20 (0 + 20) is less then 100, which it is. You want to update i:

i = i + 20

or a shorthand:

i += 20

#3

thanks man,

what is the code if i want i to jump in 20?


#4

i+=20 will increases i in steps by adding 20 each time and updating the variable