Google News
logo
Scala - Interview Questions
What is for-comprehension in Scala?
In Scala, for loop is known as for-comprehensions. It can be used to iterate, filter and return an iterated collection. The for-comprehension looks a bit like a for-loop in imperative languages, except that it constructs a list of the results of all iterations.

Example :
object MainObject {  
   def main(args: Array[String]) {  
        for( a <- 1 to 10 ){  
         println(a);  
      }  
   }  
}  ​
Advertisement