Skip to content

Instantly share code, notes, and snippets.

@abloom
Created November 7, 2011 00:15
Show Gist options
  • Select an option

  • Save abloom/1343851 to your computer and use it in GitHub Desktop.

Select an option

Save abloom/1343851 to your computer and use it in GitHub Desktop.
arr = [1, 2, 3, 4, 5, 6, 7, 8]
break for num in arr when num % 2 == 0
alert(num)
@toothrot

toothrot commented Nov 7, 2011

Copy link
Copy Markdown

how is that better than

array = [1, 2, 3, 4]
for num in array
  break if num % 2 == 0
alert(num)

@abloom

abloom commented Nov 7, 2011

Copy link
Copy Markdown
Author

they both compile to the same JS.

the weird part is that num is accessible after the loop is complete. side effect of using a for loop.

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