+ 2

How do i increase the increment in javascript loops

in incrementation while using ++ the no. increases by 1 . what if i want it to increase by 2

22nd Feb 2018, 9:24 AM
Kai Fang
3 Respuestas
+ 3
for(var i = 0; i < 100; i += 2)
22nd Feb 2018, 9:31 AM
Kevin Eldurson
Kevin Eldurson - avatar
+ 3
The full write of adding a value to another is: result = first_value + second_value; ... with first_value and second_value as litteral values and/or variable identifier names, and result as variable identifier mandatory. If you want to update a variable (use it as one of the value to be added) you simply write: result = result + value; ... with value as litteral or variable. The comes the shorthand writting; to do same (update a variable) you can write: result += value; ... wich do exactly the same, with value still litteral or variable. In special case of value is litteral equal to one: result = result + 1; is equivalent to: result += 1; ... as we previously explained. But you can also do shorter: result++; ... or even: ++result; ... but the slightly difference between those two last is beyond the scope of this answer (search in Q&A or internet, this subject had already been discussed too much times)
22nd Feb 2018, 10:35 AM
visph
visph - avatar
- 1
I don't really understand the question. An increment is an increase. Could you please explain what you want to know? edit: thanks for adding a description. don't mess with Texas' answer is what you were looking for
22nd Feb 2018, 9:27 AM
Alex
Alex - avatar