IOS运算符

分配符号 = 不会返回一个值,这样可以防止因粗心将 ==写成 赋值运算符而引起错误,在编译阶段就会报错

+ - * / % 会检查值是否溢出

可以对浮点数执行取余运算

支持范围运算符 a..b 和 a...b

var x1 :UInt8 = 12
var x2 :UInt8 = 15
var x3 :UInt8 = 30
x3 = x2 * x1
println(x3)
var x4 = 8%2.5
println(x4)
var x5 = 3.5%2
println(x5)

如果x1和x2的积大于255,会报错因为 x3是 UInt类型

 

范围运算符

for index in 1...5{
    println("\(index) times 5 is \(index * 5)")
}

let names = ["apple","banana","orange"]

let count = names.count
for i in 0..<3{
    println("the fruit \(i) is \(names[i])")
}

结果为

1 times 5 is 5

2 times 5 is 10

3 times 5 is 15

4 times 5 is 20

5 times 5 is 25

the fruit 0 is apple

the fruit 1 is banana

the fruit 2 is orange

字符和字符串

let money: 

 

posted @ 2014-07-30 23:50  小刘_php  阅读(98)  评论(0)    收藏  举报