Mick F
Mick F

Reputation: 7439

How to nest loops using outer index in inner start evaluation in CoffeeScript?

How to write two nested loops in CoffeeScript: where the inner loop is using the outer loop current index as its initial value?

ie

for (int i = 0; i < array.size(); i++) {
    for (int j = i; j < array.size; j++) {
        ...
    }
}

Thanks!

Upvotes: 1

Views: 51

Answers (2)

user4075294
user4075294

Reputation: 36

Most succinct way I could think of:

for item, i in array    
    for item, j in array when j >= i

Upvotes: 2

dfsq
dfsq

Reputation: 193261

Try something like this, maybe:

for i in array
  for j in [i ... array.size()]
    console.log i, j

Upvotes: 0

Related Questions