TL ; DR:
A for-in loop over a dictionary visits every entry. (fruit, amount) splits each one into its key and its value.
let stock = ["apples": 5, "pears": 2]
for (fruit, amount) in stock {
print(fruit, amount)
}
// pears 2
// apples 5 (in any order)
Full lesson:
A loop can visit every entry of a dictionary, one at a time. The loop body runs once per key.
(fruit, amount) splits each entry. The key comes first, then the value.
Loop over stock.keys to get only the keys.
Don't need the key? Write _ in its place, as in for (_, amount) in stock. Swift warns about a name you never use.
The order: a Swift dictionary has no fixed order. It can even change from one run to the next. A total or a count comes out the same in any order. Those are safe answers.
Your task
A game keeps each player's points in scores. The variables total and count start at 0.
Loop over scores. Add every player's points to total. Count the players with 10 points or more in count.
The loop needs only the points, not the names. The code at the bottom prints both.
Expected output:
43
2Free plan: 30 tutor messages. PRO is unlimited.
