for loop on scala code example
Example 1: how loop in scala
val lengths = for (e <- names) yield {
// imagine that this required multiple lines of code
e.length
}
Example 2: how loop in scala
for (n <- names) println(n)
for (n <- names) println(n.capitalize)
for (n <- names) {
// imagine this requires several lines
println(n.capitalize)
}