This is a draft cheat sheet. It is a work in progress and is not finished yet.
Variables
|
|
baz = foo + ' and oranges'
|
val baz = foo + ' and oranges'
|
|
Vals are immutable in Scala. Create a var instead |
|
|
|
|
foo, bar = [1, 2, 3], [1,2,3]
|
val foo, bar = Array(1, 2, 3)
|
foo[0] = 4
#Changes only foo |
bar(0) = 4
// changes only bar |
|
|
|
|
Control Statements
|
val foo = if (x > 0) 1 else -1
|
|
|
|
if (foo.isInstanceOf[String]) { print("Foo is a string!") } else if (foo.isInstanceOf[Int]) { print("Foo is an int!") } else { print("I dont know what foo is...") }
|
|
while (n < 5) { nlist += n n += 1 } |
|