Understanding Scope on Scala's For Loops (For Comprehension)
Posted
by T. Stone
on Stack Overflow
See other posts from Stack Overflow
or by T. Stone
Published on 2010-05-29T22:31:46Z
Indexed on
2010/05/29
23:42 UTC
Read the original article
Hit count: 173
In Chapter 3 of Programming Scala, the author gives two examples of for loops / for comprehensions, but switches between using ()'s and {}'s. Why is this the case, as these inherently look like they're doing the same thing? Is there a reason breed <- dogBreeds
is on the 2nd line in example #2?
// #1 ()'s
for (breed <- dogBreeds
if breed.contains("Terrier");
if !breed.startsWith("Yorkshire")
) println(breed)
// #2 {}'s
for {
breed <- dogBreeds
upcasedBreed = breed.toUpperCase()
} println(upcasedBreed)
© Stack Overflow or respective owner