0

Under normal circumstances (vanilla JS) I might do something like this -

var mystring = "foo";
for(i = 0; i < mystring.length; i++) {
    console.log(i);
}

Which will return [0,1,2]`

I cannot find the syntax to produce that behavior in LiveScript. The closest I have come is this -

 mystring = \foo
 for i from 0 to my.length-1 // note the -1
     console.log i

which compiles to this JavaScript -

var mystring, i$, to$, i;
mystring = 'foo';
for (i$ = 0, to$ = mystring.length - 1; i$ <= to$; ++i$) {
  i = i$;
  console.log(i);
}

This also returns [0,1,2].

If I do not include the -1 the array returned is [0,1,2,3] which is expected because of how LiveScript compiles to JavaScript in this case.

Is it not possible to get a pure 'less than' condition in LiveScript?

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119

1 Answers1

1

You want to use til, not to

for i from 0 til my.length

LiveScript loops

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • *smacks forehead* I have been looking at that section of the docs all morning and somehow - perhaps due to tunnel vision - did not see it. – Jay Blanchard Aug 01 '14 at 17:36