字符:
Swift中的字符串不是指针,而是实际的值
用Character定义一个字符
countElements(字符串)//计算字符个数
循环
//如果不需要知道区间内每一项的值,可以使用 _ 来代替变量名忽略对该值的访问
for _ in 1...power
{
answer*=base
}
let numberOfLegs = ["spider":8,"ant":6,"cat":4]
for(animalName ,legCount) in numberOfLegs
{
println("\(animalName):\(legCount)")
}
// 贯穿
let integer = 5
var desc = "The number \(integer) is"
switch integer {
case 2,3,5,7,11:
desc+=" a prime number,and also"
fallthrough //贯穿关键字
default:
desc+=" an interger"
}
println("desc is \(desc)")
//标签语句
var score = [86,77,87,-4,89,99]
First: for s in score
{
switch s/10
{
case 10:
continue
case 9:
println("\(s)分为优秀")
case 8:
println("\(s)分为良好")
case 7:
println("\(s)分为中等")
case 0:
break First
default:
println("\(s)分没有及格")
}
}