Reputation: 339
I've decided to learn coffeescript. Downloaded it today and was playing around with it in the cli but i keep getting odd errors for basic code that works here: https://coffeescript.org/#try:for%20i%20in%20%5B0..5%5D%0A%20%20%20%20console.log%20%22Hello%20%22%20%2B%20i%20
here's an example:
>coffee -v
CoffeeScript version 2.3.2
>coffee -c
coffee> for i in [0..5]
[stdin]:1:16: error: unexpected end of input
basically
for i in [0..5]
returns the error:
[stdin]:1:16: error: unexpected end of input
despite it working perfectly fine on the coffescript website
is something wrong with the cli version?
Upvotes: 0
Views: 27
Reputation: 6548
You need to enter the multiline input mode in the CLI to create any codeblocks that need indentation.
Once inside the CLI use CTRL
+ v
(if you use a shell / CMD where this is used to paste, try CTRL
+ SHIFT
+ v
You should see the prompt changes from coffee>
to ------>
.
Don't forget to use indentation for the inside of your for loop.
Once you've finished your block, hit ENTER
and use CTRL
+ v
to execute the multi-line block.
writing a loop in normal mode raises an error
coffee> for i in [1,2,3]
[stdin]:1:17: error: unexpected end of input
for i in [1,2,3]
^
First entering multi-line mode (don't forget indentation after the first line)
------> for i in [1,2,3]
....... i * i - i
Now hit enter and exit multi-line mode to execute. As with any execution in the CLI, the output of the expression (loop in this case) will be printed:
[ 0, 2, 6 ]
Upvotes: 1