Skip to content

Instantly share code, notes, and snippets.

@ccapndave
Created December 7, 2011 17:36
Show Gist options
  • Save ccapndave/1443726 to your computer and use it in GitHub Desktop.
Save ccapndave/1443726 to your computer and use it in GitHub Desktop.
Nested loops
for x in [0...3]
for y in [0...3]
doSomething x, y
# Is there a clever Coffee way to do this is a single loop/line?
@codelahoma
Copy link

If you put a little work in ahead of time, you can do:

unroll = (arr1,arr2) ->
 result = []
 for x in arr1
  for y in arr2
   result.push [x,y]
 result

for [x, y] in unroll [1..3], [1..3]
 console.log "x: #{x}, y: #{y}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment