Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Scala For loop

object ForLoop {
    def main(args:Array[String]) {
        val planets = List("Mercury", "Venus", "Earth", "Mars")
        for(name <- planets) println(name)
        for(name <- planets) {
           println(name)
        }
    }
}
object ForLoopRange {
    def main(args:Array[String]) {
        for(i <- 10 to 1 by -1) {
           println(i)
        }
    }
}