v For Loop A Map - Scala

For Loop A Map

If you want to learn more, check out Scala Cookbook and Programming in Scala.

Create A Map

val vehicles = Map("vehicle_type" -> "Tank", 
                   "number" -> 21)

Loop With Value And Index

// Create a value for the returned values, for each key and value in the map,
val numberOfVehicles = for ((key, value) <- vehicles) yield {
                         // Return the values
                         value
                       }
// View the returned values
numberOfVehicles
List(Tank, 21)