Scala Language For Expressions


  • for {clauses} body
  • for {clauses} yield body
  • for (clauses) body
  • for (clauses) yield body


forRequired keyword to use a for loop/comprehension
clausesThe iteration and filters over which the for works.
yieldUse this if you want to create or 'yield' a collection. Using yield will cause the return type of the for to be a collection instead of Unit.
bodyThe body of the for expression, executed on each iteration.