Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coffeescript for loop

Tags:

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) {...}
like image 406
Curtis Avatar asked Dec 20 '12 19:12

Curtis


2 Answers

scale = maxVal
while scale >= 0
  ...
  scale -= stepSize

There's a good tool for converting JS to Coffeescript: http://js2.coffee/

like image 20
Anatoliy Kukul Avatar answered Oct 10 '22 00:10

Anatoliy Kukul


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

like image 138
hexid Avatar answered Oct 10 '22 01:10

hexid