For Expressions

Download scala eBook


  • 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.

Related Examples


210 Contributors: 6
Monday, October 24, 2016
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial:

Download eBook