For loops

Iterate by incrementing or decrementing a value

for var i = 0; i < 10; i++ {
  // do something
}

// alternative:
for i in 0...10 {
  // do something
}

To iterate over an array in Swift:

for x in ["a", "b", "c"] {
  // do something
}

To iterate over a dictionary in Swift:

for (key, val) in ["foo": 23, "bar": 244, "baz": 42] {
  // do something
}
 

swiftfreak

 

Leave a Reply

Your email address will not be published. Required fields are marked *