Skip to content

Instantly share code, notes, and snippets.

@k2052
Created February 12, 2012 20:33
Show Gist options
  • Save k2052/1810744 to your computer and use it in GitHub Desktop.
Save k2052/1810744 to your computer and use it in GitHub Desktop.
For loops in coffeescript. Be careful how you port your code.
# This will never end because i++ wont be reached more than three times.
i = 0
i = 0
while i <= 10
continue if i is 3
console.log "The number is " + i
console.log "\n"
i++
# This will simply skip when i = 3 as intended
i = 0
i = 0
while i <= 10
if i is 3
i++
continue
console.log "The number is " + i
console.log "\n"
i++
@showell
Copy link

showell commented Feb 12, 2012

for i in [0..10]
  continue if i is 3  
  console.log "The number is " + i

@showell
Copy link

showell commented Feb 12, 2012

This is the JS.

var i;

for (i = 0; i <= 10; i++) {
  if (i === 3) continue;
  console.log("The number is " + i);
}

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