Yong Quan Yong Quan - 1 month ago 10
jQuery Question

Can I set the factor/speed of i++ and i--?

i++
or
i--
adds or deducts the value of
i
by 1 each time it is executed.

Is there a way to change the factor of adding or deducting of
i++
and
i--
to, for example, 5?

Meaning that each time
i++
or
i--
is executed, it adds or deducts its value by 5 instead of only 1.

For example:

var i = 0;
i++;


Instead of having output of
1, 2, 3, 4...
, can it get an output of
5, 10, 15, 20...
or
6, 12, 18, 24...
?

Answer

Try this:

var i = 0;  
i = i + 5;

or

i += 5;

It will increment i by value 5