Swift中if語句和OC中if語句的區別:
1.if后面的()可以省略掉
2.必須有明確的真假,沒有非0(nil)即真,()中的語句是Bool類型,該類型有true/false兩個值.
let a = 10
if a > 0 {
print("a大于0")
}
if a != 0 {
print("a不等于零")
}
else if的使用:
let score = 88
if score < 0 || score > 100 {
print("不合理的額分數")
}else if score < 60 {
print("不及格")
}else if score < 80 {
print("良好")
}else if score < 100 {
print("優秀")
}