This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 3.1, “How to loop over a collection with for and foreach (and how a for loop is translated)”
Problem
You want to iterate over the elements in a collection, either to operate on each element in the collection, or to create a new collection from the existing collection.