Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Last active December 27, 2015 11:29
Show Gist options
  • Save animatedlew/7318822 to your computer and use it in GitHub Desktop.
Save animatedlew/7318822 to your computer and use it in GitHub Desktop.
Scala Ranges & Loops
object Loops extends App {
print("for (i <- 1 to 10)\n\t")
// for/Range using to
for (i <- 1 to 10) {
print("#" + i)
}
print("\nfor (i <- 1 until 10)\n\t")
// for/Range using until
for (i <- 1 until 10) {
print("#" + i)
}
print("(1 to 10).foreach\n\t")
// Rich.to() using foreach
(1 to 10).foreach(i => print("#"+ i))
print("(1 until 10).foreach\n\t")
// Rich.until() using foreach
(1 until 10).foreach(i => print("#"+ i))
println()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment