Swift中的格式控制符和元祖
(1)首先介绍一下元祖,元祖是关系型数据库中 例如学生表中的姓名,年龄,电话等
定义如下
var studentinfo = ("jhon",29,"123456") println(studentinfo.0)
//元组本身是以一个整体存在的,如果用下标获取元祖的某一项的数据时 //可以通过点语法加下标的形式得到,这叫元祖的拆包 println("name:\(studentinfo.0),age:\(studentinfo.1),phone:\(studentinfo.2)") var teacherinfo = (name:"teacher1",age:30,phone:"123456") //打印整个元组的信息 println(teacherinfo) //打印元祖name的信息,其实teacherinfo中的name,age,phone是用来做标签的 //下面这两行是等价的输出的都是teacher1 println(teacherinfo.name)
<p class="p1">println<span class="s1">(</span>teacherinfo<span class="s1">.</span>0<span class="s1">)</span></p>
for(var i = 0;i<100;i++) { println("\(i)") } //Swift特有的for--in--循环 //循环变量的范围,2个点表示不包含100,3个点表示包含0和100 for j in 0...100 { println("\(j)") } //if语句 var number1 = 45 if(number1>90) { println("good") }else if(number1<90&&number1>60) { println("bad") }else { println("so bad") } //func sumof(number:int...)->int{ //} let interestringNumber=[ "prime":[2,3,5,7,11,13], "Fibonaccl":[1,1,2,3,5,8], "Square":[1,4,9,16,25], ] var largest = 0; for(kind,numbers)in interestringNumber{ for number in numbers { if number>largest { largest = number } } }
Swift学习——格式控制符和元组流程控制(二),布布扣,bubuko.com
原文地址:http://blog.csdn.net/jingjingxujiayou/article/details/32943331