//: Playground - noun: a place where people can play import UIKit // for 循环 //你可以使用for-in循环来遍历一个集合里面的所有元素,例如由数字表示的区间、数组中的元素、字符串中的字符。 for index in 1...5{ println(index); } //如果你不需要知道区间内每一项的值,你可以使用下划线(_)替代变量名来忽略对值的访问 var count = 3; var one = 1; var two = 2; for _ in 1...count{ one *= two } // 遍历数组 var arr1 = ["E","n","d","a"]; for name in arr1{ println(name); } // key + value var arr2 = [1:"E",2:"n",3:"d",4:"a"]; for (key,value) in arr2{ println("\(key)==>\(value)") } // 遍历字符串 var names = "MyNameisEnda"; for name in names{ println("\(name)"); } // for 条件递增 for var index = 0;index<3;++index{ println(index); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。