Stats

210 Contributors: 6
2016-10-24
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

For Expressions

Download scala eBook

Syntax

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

Parameters

ParameterDetails
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