Reputation: 201
I am trying to convert some apple chart examples from javascript to coffeescript. Having a tough time trying to figure out how to write this for loop in coffee script. Thanks for any help in advance
for (scale = maxVal; scale >= 0; scale -= stepSize) {...}
Upvotes: 20
Views: 28091
Reputation: 2016
scale = maxVal
while scale >= 0
...
scale -= stepSize
There's a good tool for converting JS to Coffeescript: http://js2.coffee/
Upvotes: 10
Reputation: 3811
This loop will increment by the negative of stepSize.
maxVal = 10
stepSize = 1
for scale in [maxVal..0] by -stepSize
console.log scale
However, if stepSize is actually 1, then
maxVal = 10
for scale in [maxVal..0]
console.log scale
would produce the same result
Upvotes: 28