Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple loop in coffeescript

Tags:

coffeescript

I have this code:

count = $content.find('.post').length;              
for x in [1...count]
    /*
    prev_el_height += $("#content .post:nth-child(" + x + ")").height();
    */
    prev_el_height += $content.find(".post:nth-child(" + x + ")").height();

I expected this to turn into

for (x = 1; x < count; x++) { prev_el ... }

but it turns into this:

for (x = 1; 1 <= count ? x < count : x > count; 1 <= count ? x++ : x--) {

Can somebody please explain why?

EDIT: How do I get my expected syntax to output?

like image 255
OZZIE Avatar asked Apr 20 '12 12:04

OZZIE


1 Answers

In CoffeeScript, you need to use the by keyword to specify the step of a loop. In your case:

for x in [1...count] by 1
  ...
like image 135
Trevor Burnham Avatar answered Dec 27 '22 07:12

Trevor Burnham