This is a very basic Javascript question. See, I have a for loop which starts like this
for (i=0;i<=negativeorpositivenumber;i++) {
As the name suggests, the positiveornegativenumber variable can contain either a positive or negative number. As a result, if said variable is positive, the for loop works. If it is negative, the loop exits immediately because i is already larger than negativeorpositivenumber.
Is there a way, without using two for loops (one for negative and one for positive) to have this work both ways? So change i<= to i>= and i++ to i-- if the variable negativeorpositivenumber is negative?
I suppose this question could also apply to more than one language as well.
EDIT: perhaps I should've made this more clear. I can't use absolute value because the value of i actually needs to count down. Thanks to all the people who were helpful and answered using Math.abs, however.