This content originally appeared on flaviocopes.com and was authored by flaviocopes.com
This tutorial belongs to the Swift series
for-in
loops can be used to iterate a specific amount of times, using a range operator:
for index in 0...3 {
//iterate 4 times, `index` is: 0, 1, 2, 3
}
You can iterate over the elements of an array or set:
let list = ["a", "b", "c"]
for item in list {
// `item` contains the element value
}
And on the elements of a dictionary:
let list = ["a": 1, "b": 2, "c": 2]
for (key, value) in list {
// `key` contains the item key
// `value` contains the item value
}
This content originally appeared on flaviocopes.com and was authored by flaviocopes.com
flaviocopes.com | Sciencx (2021-05-25T05:00:00+00:00) Swift Loops: `for-in`. Retrieved from https://www.scien.cx/2021/05/25/swift-loops-for-in/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.