A
A
Artem Typan2015-04-17 17:49:59
CoffeeScript
Artem Typan, 2015-04-17 17:49:59

CoffeeScript for loop?

function createGrid( section, dimensions ) {
  var grid = new GridLayout({
    dimensions: dimensions
  });
  
  var surfaces = [];
  grid.sequenceFrom(surfaces);
  
 for(var i = 0; i < dimensions[0] * dimensions[1]; i++) {
    surfaces.push(new Surface({
      content: section + ' ' + (i + 1),
      size: [undefined, undefined],
      properties: {
        backgroundColor: "hsl(" + (i * 360 / 8) + ", 100%, 50%)",
        color: "#404040",
        textAlign: 'center'
      }
    }));
  }
  return grid;
}

How to write
for(var i = 0; i < dimensions[0] * dimensions[1]; i++)
in Coffee? Thanks in advance for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2015-04-17
@typan

In coffeescript, the for loop can only walk through objects/lists/generators.
For your case, you will have to use while:

i = 0
while i < dimensions[0] * dimensions[1]
  # ...
  i += 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question