Search code examples
javascriptcoffeescriptcode-conversion

For Loops Using Javascript


I'm trying to convert this code from Javascript to CoffeeScript:

for (var i = 0; i < names.length; i++) {
    str += "Hello" + names[i] + "!<br />";
}

But at the CoffeeScript project home page there is only a simple example of how to do for loops and I can't understand it quite well too, so how can I make convert that to CoffeeScript?


Solution

  • Try this:

    str += 'Hello' + name + '!<br />' for name in names