Skip to content

Instantly share code, notes, and snippets.

@deanwampler
Created October 11, 2020 21:02
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 deanwampler/98647681a702c13da41342bf51684915 to your computer and use it in GitHub Desktop.
Save deanwampler/98647681a702c13da41342bf51684915 to your computer and use it in GitHub Desktop.
Scala 2 vs. 3 optional control syntax changes.
for (i <- 0 until 5) println(i) // Original syntax
for i <- 0 until 5 do println(i) // New syntax
for i <- 0 until 5 yield 2*i
for i <- 0 until 10
if i%2 == 0
ii = 2*i
yield ii
val i = 10
if (i < 10) println("yes") // Original syntax
else println("no")
if i < 10 then println("yes") // New syntax
else println("no")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment