Last active
December 27, 2015 11:29
-
-
Save animatedlew/7318822 to your computer and use it in GitHub Desktop.
Scala Ranges & Loops
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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