Adding 2 variables using for loop


Hello, I am wondering if I could combine 2 variables using the loop technique, for example:

for (var i = 1; i < 101; i-= 20) {


This would represent some health of something like a building or troop degrading due to an attacker

for (var x = 0; x < 351; x+= 43.75) {


This could be some health being placed over a troop or building which would gradually give them health

How would I use these 2 in conjunction?


Something like this:

for(var i = 0, j = 20; i < 10 && j > 0; i++, j--) {
    console.log(i, j);


Sure, you can. But it affects readability of your code and it's really not a good idea.


Thank you for the assistance, I will try playing around with the code and see what I can do.


You're welcome.

In case of any specific problems we are here to help you :slight_smile:


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