Skip to content

Instantly share code, notes, and snippets.

@danyaljj
Created June 26, 2015 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danyaljj/aee2ac7987e96bd1305f to your computer and use it in GitHub Desktop.
Save danyaljj/aee2ac7987e96bd1305f to your computer and use it in GitHub Desktop.
Scala summary
== 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