3

What's the equivalent CoffeeScript syntax of the native JS' multiple variables for-loop?

for(var a = 0, b = 0; a < 100; a++, b += 10)
{
  console.log(a, b);
}
0

1 Answer 1

2

Instead of a for construct like JavaScript's, CoffeeScript relies on comprehensions and ranges. From the documentation:

The only low-level loop that CoffeeScript provides is the while loop.

You could do something involving a range for a, with b being updated manually:

b = 0
for a in [0..99]
  console.log a b
  b += 10

Or use that while:

a = 0
b = 0
while a < 100
  console.log a b
  ++a
  b += 10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.