var cutlery: Set = ["fork", "knife", "spoon", "spoon"] var flowers:Set<Character> = ["","",""] var utensils = Set<String>() var trees = Set<Character>()
Control Flow
-for loop statement
-switch statement
-if else statement
For-in loops take the form:
for item in Collection {
statements to execute on each item
}
import UIKit import Foundation for var index = 99; index > 0; --index { print("\(index) bottles of beer on the wall. \(index) bottles of beer. Take one down, pass it around ...") }
var demoString = "Swift enumeration is so fast!" for character in demoString.characters { print(character) }
let intArray = [7, 21, 25, 13, 1] var sum = 0 for value in intArray { sum += value }
var movieDict = ["star wars":"Geroge Lucas", "Point Break": "Kathryn Biegelow", "When Harry Met Sally": "Rob Reiner", "The Dark Knight": "Christopher Nolan"] for (movie, director) in movieDict { print("\(director) directed \(movie)") } var animalGroupsDict = ["whales":"pod", "geese":"flock", "lions":"pride"] for (animals, animalGroup) in animalGroupsDict { print("Many \(animals) form a \(animalGroup).") }