Swift Loops: `for-in`

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 arr…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Swift Loops: `for-in`." flaviocopes.com | Sciencx - Tuesday May 25, 2021, https://www.scien.cx/2021/05/25/swift-loops-for-in/
HARVARD
flaviocopes.com | Sciencx Tuesday May 25, 2021 » Swift Loops: `for-in`., viewed ,<https://www.scien.cx/2021/05/25/swift-loops-for-in/>
VANCOUVER
flaviocopes.com | Sciencx - » Swift Loops: `for-in`. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/25/swift-loops-for-in/
CHICAGO
" » Swift Loops: `for-in`." flaviocopes.com | Sciencx - Accessed . https://www.scien.cx/2021/05/25/swift-loops-for-in/
IEEE
" » Swift Loops: `for-in`." flaviocopes.com | Sciencx [Online]. Available: https://www.scien.cx/2021/05/25/swift-loops-for-in/. [Accessed: ]
rf:citation
» Swift Loops: `for-in` | flaviocopes.com | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.