1 在特定的范围内计数循环,结构为
for loopVar in startNumber...endNumber
关键字in 的后面依次为起始数字,三个句点和结束数字,示例:
var loopCount :Int=0
for loopCount in 1...10 {
print ("#\(loopCount)")
}
2 变种语法
for loopCount in 1..<10 {
//print
}
3 老式for循环
for loopCount=0;loopCount<10;loopCount++) {
//do something
}
开始使用playground

流程控制就是决策
if (true /false ) {
//do sth
}else
{
//do other thing
}
swift 比较运算符
==, != ,> , < , >= ,<=
if true /false {
//do sth1
}else if true /false {
//do sth2
}else if true /false {
//do sth3
}else {
//do oter thing
}
switch case default 类似C,但是不限于整形数字和enum,还可以用于String, 另外switch-case 在swift中不需要使用break
for three in threeArray {
switch three {
case "Cak" :
print ("Furniture")
case "Pecan":
print ("Pie")
case "Maple":
print ("Syrup")
default:
print ("Wood")
}
}
while 循环
while someCondition {
//do sth
}
repeat {
//do sth
} while someCondition
跳出循环使用break
//Todo。swift中怎么没有continue呢,如果仅仅退出当前循环呢?
原文:http://www.cnblogs.com/wencairen/p/6819010.html