Introduction
Control Flow
Syntax
Iterating Through a Collection
for with yield
Filtering with if
Introduction
We sometimes come across scenarios where a block of code needs to be executed multiple times. The for expression is one such control structure that does just that. Scala’s for expression provides a wide variety of ways to express iterations depending on the object you want to iterate over; the simplest being a collection.
Control Flow
Let’s look at the general control flow of a for expression below.