Created
June 26, 2015 00:27
-
-
Save danyaljj/aee2ac7987e96bd1305f to your computer and use it in GitHub Desktop.
Scala summary
This file contains 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
== Scala notes | |
== main function: | |
def main(args: Array[String]) { | |
println("Hello, world!") | |
} | |
== looping | |
// both equivalent to for(int i = 0; i < nvals; i++) | |
for (i <- 0 to nvals - 1) something(i) | |
for (i <- 0 until nvals ) something(i) | |
(0 until nvals)foreach{ i => something } | |
// nested: | |
for { | |
x <- 0 until 5 | |
y <- 0 until 10 | |
} { | |
println(s"x = $x, y = $y") | |
} | |
// the ranges can be dependant on each other too! | |
for { | |
x <- 0 until 5 | |
y <- 0 until 2*x | |
} { | |
println(s"x = $x, y = $y") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment