swift 基础笔记七(for循环)
发布时间:2020-12-14 02:04:32 所属栏目:百科 来源:网络整理
导读://: Playground - noun: a place where people can playimport UIKit// for 循环//你可以使用for-in循环来遍历一个集合里面的所有元素,例如由数字表示的区间、数组中的元素、字符串中的字符。for index in 1...5{ println(index);}//如果你不需要知道区间内
//: 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); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |