Iterative access to the swift array

Source: Internet
Author: User

1You can get through for-.in loops to iterate over the value of the entire array. 2  forIteminchShoppinglist {3 println (item)4 }5 //Six Eggs6 //Milk7 //Flour8 //Baking Powder9 //BananasTen If you want to get the index of each element and its corresponding value, you can use the global enumerate method to iterate over the array. The enumerate method returns a tuple that consists of index values and corresponding element values for each element. You can convert a member of a tuple into a variable or constant to use: One  for(Index, value)inchEnumerate (shoppinglist) { Aprintln"Item \ (index + 1): \ (value)") - } - //Item 1:six Eggs the //Item 2:milk - //Item 3:flour - //Item 4:baking Powder - //Item 5:bananas

Iterative access to the swift array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.