This is my first day of studying Scala (using the "Beginning Scala" book). When I read the for
loops in Scala, there are 2 examples:
val books = List("Beginning Scala", "Beginning Groovy", "Beginning Java", "Scala in easy steps", "Scala in 24 hours")
[1]
for (book<-books if book.contains("Scala")) println(book)
[2]
for { book <- books
bookVal = book.toUpperCase()
}
println(bookVal)
The thing that confused me is:
In [1] for
uses parentheses "()
" to wrap the loop control block while in [2] it uses curly braces "{}
". I wonder if this is just different syntax but the same purpose or if they actually mean something different?
Thanks